我有一个示例.csv,导入为df.csv,如下:
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
Run Code Online (Sandbox Code Playgroud)
我想检查 .pandastest1['Description']中的字符串 test1['Ethnicity']。这应该返回第 0、3、4 和 5 行,因为描述字符串包含种族列中的字符串。
到目前为止,我已经尝试过:
df[df['Ethnicity'].str.contains('French')]['Description']
Run Code Online (Sandbox Code Playgroud)
这将返回任何特定的字符串,但我想遍历而不搜索每个特定的种族值。我还尝试将列转换为列表并进行迭代,但似乎无法找到返回行的方法,因为它不再是 DataFrame()。
先感谢您!