【发布时间】:2016-11-02 20:36:48
【问题描述】:
我有一个例子.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
我想检查 pandas test1['Description'] 中 test1['Ethnicity'] 中的字符串。这应该返回第 0、3、4 和 5 行,因为描述字符串包含种族列中的字符串。
到目前为止我已经尝试过:
df[df['Ethnicity'].str.contains('French')]['Description']
这会返回任何特定的字符串,但我想在不搜索每个特定种族值的情况下进行迭代。我还尝试将列转换为列表并进行迭代,但似乎找不到返回行的方法,因为它不再是 DataFrame()。
提前谢谢你!
【问题讨论】:
标签: python string pandas dataframe substring