I have an example .csv, imported as df.csv, as follows:
Ethnicity, Description
0 French, Irish Dance Company
1 Italian, Moroccan/Algerian
2 Danish, Company in Netherlands
3 Dutch, French
4 English, EnglishFrench
5 Irish, Irish-American
I'd like to check the pandas test1['Description']
for strings in test1['Ethnicity']
. This should return rows 0, 3, 4, and 5 as the description strings contain strings in the ethnicity column.
So far I've tried:
df[df['Ethnicity'].str.contains('French')]['Description']
This returns any specific string, but I'd like to iterate through without searching for each specific ethnicity value. I've also tried converting the columns to lists and iterating through but can't seem to find a way to return the row, as it is no long a DataFrame().
Thank you in advance!
the ever popular double apply:
Timing
jezrael's answer is far superior
You can use
str.contains
with values in columnEthnicity
convertedtolist
and thenjoin
by|
what is inregex
or
:It looks like you can omit
tolist()
: