首页 > 解决方案 > 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                                                              

标签: pythonpandas

解决方案


你能提供csv文件吗?这个例子对我来说很好。

无论如何,您只需使用以下方法即可实现您想要的:

df.dropna(subset=['rt', 'comment2'])[['word','value','color','rt']]

推荐阅读