Is there an easy straightforward already existing way to search a DataFrame with a String wildcard in a specific column, and then print the found entries/rows?
For example, you want to search if a certain name is in the data, but donβt remember it exactly. You wish to search with an approximate wildcard, such as *batman* (where the stars in this denote the wildcards).
[c for c in names(dd) if occursin("batman", string(c))]? For any more complex patterns I donβt see how you get by without regex.
You also might have noticed that DataFrames has a convenience function that improves error messages for typos of column names - if the column youβre requesting is close to the name of an existing column it will suggest that similarly named column. So if itβs really just about not exactly remembering a name you can just try an approximate name and let the error message help you.
Ah sorry I read the question as asking about the name of a column rather than the data within a column. That said, why donβt you broadcast occursin like
The use of occursin came to mind, but now youβve shown me how to use it in this particular context.
Standing now in this case on your shoulders, Iβm wondering if I can make a general quick function with this information. If I have time, I hope to do so.
function findsomethingsomewhere(smt, df)
positives = fill(false, nrow(df))
for col in eachcol(df)
if eltype(col) <: AbstractString
positives .= positives .| occursin.(smt, col)
end
end
df[positives, :]
end