【发布时间】:2019-02-17 09:28:44
【问题描述】:
我试过了
df = df[~df['event.properties.comment'].isin(['Extra'])]
问题是如果该列正好包含“Extra”,它只会删除该行,我需要删除包含它的行,甚至作为子字符串。
有什么帮助吗?
【问题讨论】:
标签: python string pandas dataframe series
我试过了
df = df[~df['event.properties.comment'].isin(['Extra'])]
问题是如果该列正好包含“Extra”,它只会删除该行,我需要删除包含它的行,甚至作为子字符串。
有什么帮助吗?
【问题讨论】:
标签: python string pandas dataframe series
您可以使用 or 条件来检查字符串的多个条件,根据您的要求,如果文本具有“Extra”或“~”,您可以保留文本。 考虑df
vals ids
0 1 ~
1 2 bball
2 3 NaN
3 4 Extra text
df[~df.ids.fillna('').str.contains('Extra')]
输出:
vals ids
0 1 ~
1 2 bball
2 3 NaN
【讨论】: