我正在读取目录中的 .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”
我无法弄清楚我需要修复哪一部分?
我有这样的数据帧
id 2013 Profits 2001 Revenues 1999 Assets...
31 xxxx xxxx xxxx
...
Run Code Online (Sandbox Code Playgroud)
我想删除不以'201'开头的列(我只想保留数据2010和转发).
我怎样才能做到这一点?