python - 如果 Dataframe 中的行包含某些字符串删除

标签 python pandas python-2.7 numpy

如果它们包含某个字符串,我必须删除数据帧行中的值。
问题是行很长并且包含文本。

循环不起作用并将索引放在列表中,然后在索引上使用 .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' .与 ~你换了 TrueFalse这个数组的值。最后是 df_filtered = df[...]你只取线条,其中 'total'不包括在内。

关于python - 如果 Dataframe 中的行包含某些字符串删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55846401/

相关文章:

python - easy_install-2.7 的问题

python - 字典列表理解 - 多个条件

python - Pandas - 在 DataFrame 中的任何位置查找值索引

Python pandas 数据框,逐行聚合直至停止标准

Python kbhit() 问题

python - 如何使用Python通过knox与Hbase交互?

python - 如何移动多列? Pandas 、 python

python - 为 Python 安装 pip 时出错

python - pysvn 获取特定目录的最新修订号(不是头)

python - 将 django-rest-framework 中的超链接添加到 ModelViewSet