如果它们包含某个字符串,我必须删除数据帧行中的值。
问题是行很长并且包含文本。
循环不起作用并将索引放在列表中,然后在索引上使用 .drop 也不起作用。
column1
8
8
8
8 total <-------- This must be deleted
8
8
8
8
8
...
谢谢
最佳答案
假设您的数据框名为 df
.然后使用:
df_filtered = df[~df['column1'].str.contains('total')]
说明 :
df['column1'].str.contains('total')
将为您提供数据框列长度的数组 True
哪里df['column1']
包含 'total'
.与 ~
你换了 True
和 False
这个数组的值。最后是 df_filtered = df[...]
你只取线条,其中 'total'
不包括在内。
关于python - 如果 Dataframe 中的行包含某些字符串删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55846401/