[英]KeyError: "None of [Float64Index([34.62365962451697, 30.28671076822607, 35.84740876993872], dtype='float64')] are in the [columns]"
This is my dataframe:这是我的数据框:
x1 x2 y x2_modified
0 34.623660 78.024693 0 99.294362
1 30.286711 43.894998 0 110.085855
2 35.847409 72.902198 0 96.249345
When i try to access the column x1
, it does it perfectly:当我尝试访问列
x1
,它完美地做到了:
>>> print(df.x1)
0 34.623660
1 30.286711
2 35.847409
Name: x1, dtype: float64
But when i try to plot it,但是当我试图绘制它时
df.plot(x = df.x1, y = df.x2_modified)
It gives above error:它给出了上述错误:
KeyError: "None of [Float64Index([34.62366, 30.286710999999997, 35.847409000000006], dtype='float64')] are in the [columns]"
KeyError:“[Float64Index([34.62366, 30.2867109999999997, 35.847409000000006], dtype='float64')] 均不在 [columns] 中”
I'm not getting the reason, please help.我不明白原因,请帮忙。 Thanks.
谢谢。
If want use DataFrame.plot
only pass columns names:如果想使用
DataFrame.plot
只传递列名:
df.plot(x = 'x1', y = 'x2_modified')
If want use matplotlib.pyplot.plot
then you can pass Series
:如果想使用
matplotlib.pyplot.plot
那么你可以通过Series
:
plt.plot(df.x1, df.x2_modified)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.