这是我的数据框:
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
当我尝试访问列x1
时,它完美地完成了:
>>> print(df.x1)
0 34.623660
1 30.286711
2 35.847409
Name: x1, dtype: float64
但是当我尝试绘制它时,
df.plot(x = df.x1, y = df.x2_modified)
它给出了上述错误:
KeyError: "None of [Float64Index([34.62366, 30.286710999999997, 35.847409000000006], dtype='float64')] are in the [columns]"
我不明白原因,请帮忙。谢谢。
最佳答案
如果想要使用DataFrame.plot
仅传递列名称:
df.plot(x = 'x1', y = 'x2_modified')
如果想要使用matplotlib.pyplot.plot
那么你可以通过 Series
:
plt.plot(df.x1, df.x2_modified)
关于python - key 错误 : "None of [Float64Index([34.62365962451697, 30.28671076822607, 35.84740876993872], dtype=' float6 4')] are in the [columns]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59694029/