作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是Python新手,尤其是Pandas新手,所以我真的不知道我在做什么。我有 10 列、100000 行和 4 个字母字符串。我需要过滤掉所有列/行中不包含“DDD”的行。
我尝试使用 iloc 和 loc 来做到这一点,但它不起作用:
import pandas as pd
df = pd.read_csv("data_3.csv", delimiter = '!')
df.iloc[:,10:20].str.contains('DDD', regex= False, na = False)
df.head()
它返回一个错误:“DataFrame”对象没有属性“str”
最佳答案
我建议不要使用 for
循环,如下所示:
df[df.apply(lambda x: x.str.contains('DDD')).all(axis=1)]
仅选择字符串列
df[df.select_dtypes(include='object').apply(lambda x: x.str.contains('DDD')).all(axis=1)]
仅选择一些字符串列
selected_cols = ['A','B']
df[df[selected_cols].apply(lambda x: x.str.contains('DDD')).all(axis=1)]
关于python - 如何在Python中过滤掉具有特定字符串的多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58790897/
我正在编写一个快速的 preg_replace 来从 CSS 中删除注释。 CSS 注释通常有这样的语法: /* Development Classes*/ /* Un-comment me for
使用 MySQL,我有三个表: 项目: ID name 1 "birthday party" 2 "soccer match" 3 "wine tasting evening" 4
我是一名优秀的程序员,十分优秀!