我收到错误KeyError:'duration',当它存在时

时间:2016-11-23 00:19:59

标签: python pandas

以下代码返回错误

KeyError: 'duration'


for i in range(0, 3): 
     exam_df['duration'] = pd.to_datetime(i,(exam_df['Duration '])[i])
exam_df['grade'] = exam_df['Grade'].astype(np.int64)
exam_df.plot.scatter(x='duration', y='grade')

1 个答案:

答案 0 :(得分:3)

我认为你拼错关键'持续时间',试着改变:

exam_df['duration'] = pd.to_datetime(i,(exam_df['Duration '])[i])

使用:

exam_df['duration'] = pd.to_datetime(i,(exam_df['duration'])[i])