python - AttributeError:“DataFrame”对象没有属性“rt”
问题描述
即使我的数据框中存在属性“rt”,我仍然会收到此错误。它以前工作过,我不确定为什么现在不工作。有任何想法吗?
这就是我的代码的样子:
path1 = '/home/data/1-23.csv'
file1 = pd.read_csv(path1,skipinitialspace=True, index_col=None)
df1 = file1[~file1.rt.isna()]
df1 = file1[~file1.comment2.isna()]
df1 = df1[['word','value','color','rt']]
print(df1.head())
这是数据的外观:
resultstime,ipaddress,controller,numberitem,innernumber,label,latingp,penntype,pennname,parameter,value,eventime,word,color,correct,rt,comment2
1619906522,529a13d061460b9dd2ecdcd4dcd0b118,PennController,43,0,experimental-trial,NULL,PennController,44,_Trial_,Start,1619906424186,CHOQUE, green, v,1353,NULL
1619906522,529a13d061460b9dd2ecdcd4dcd0b118,PennController,43,0,experimental-trial,NULL,Text,word,Print,NA,1619906424186,CHOQUE, green, v,1353,NULL
1619906522,529a13d061460b9dd2ecdcd4dcd0b118,PennController,43,0,experimental-trial,NULL,Key,keypress,PressedKey,V,1619906425542,CHOQUE, green, v,1353,Wait success
解决方案
你能提供csv文件吗?这个例子对我来说很好。
无论如何,您只需使用以下方法即可实现您想要的:
df.dropna(subset=['rt', 'comment2'])[['word','value','color','rt']]
推荐阅读
- docker - Docker 每个网络端口映射
- javascript - XMLHttpRequest.upload.onprogress 不使用 HTTPS
- java - 如何在 JBoss 上部署 Java 独立应用程序以及其他 Web 应用程序
- jenkins - 将 jobdsl 命令扩展到 groovy 类的问题
- javascript - 计数计时器,记录在页面上花费的时间
- html - Github 页面问题 - (错误 404 或根本没有出现)
- processor - 计算执行时间
- python - 执行 jupyter notebook 时出错:ImportError: cannot import name '_RuleList'
- c# - 当返回行时,如何修复 reader.Read() 部分中的输入格式不正确?
- reactjs - 如何将 Redux 连接到 React 功能组件