How would I filter columns that contain a particular substring?

Hi how’s it going?

Say I have this dataframe

initial = DataFrame(:day=>["monday","monday","monday"],:name=>["bob","mike","phillis"],:temp=>["medium","high","low, medium"],:gender=>["male, female","male","female"])

Screenshot from 2020-07-08 07-14-07

How would I extract the names of the columns that contain a comma in at least one of their values?

For the above DataFrame I need it to return :temp and :gender

One way:

names(initial)[[any(occursin.(",", c)) for c ∈ eachcol(initial)]]
3 Likes

thank you!