相关疑难解决方法(0)

读取数据时删除包含某些字符串的列:python

我正在读取目录中的 .txt 文件,并希望删除包含某些特定字符串的列。

for file in glob.iglob(files + '.txt', recursive=True):
    
    cols = list(pd.read_csv(file, nrows =1))
    
    df=pd.read_csv(file,header=0, skiprows=0, skipfooter=0, usecols =[i for i in cols if i.str.contains['TRIVIAL|EASY']==False])
Run Code Online (Sandbox Code Playgroud)

当我这样做时我得到

df=pd.read_csv(文件,header=0,skiprows=0,skipfooter=0,usecols =[i for i >in cols if i.str.contains['PASS']==True])

属性错误:“str”对象没有属性“str”

我无法弄清楚我需要修复哪一部分?

根据 pandas 中包含特定字符串的列名称选择列

根据字符串条件删除列

属性错误:“str”对象没有属性“str”

删除 Pandas 中以特定字符串结尾的多列

python string dataframe pandas

4
推荐指数
1
解决办法
896
查看次数

Python/Pandas - 删除以字符串开头的列

我有这样的数据帧

id    2013 Profits   2001 Revenues    1999 Assets...
31    xxxx           xxxx             xxxx
...
Run Code Online (Sandbox Code Playgroud)

我想删除不以'201'开头的列(我只想保留数据2010和转发).

我怎样才能做到这一点?

python pandas

3
推荐指数
2
解决办法
3124
查看次数

标签 统计

pandas ×2

python ×2

dataframe ×1

string ×1