Man*_*rma 5 python plot matplotlib pandas
我正在尝试从 Pandas 数据帧创建散点图,但我不想使用 matplotlib plt。以下是脚本
df:
group people value
1 5 100
2 2 90
1 10 80
2 20 40
1 7 10
Run Code Online (Sandbox Code Playgroud)
我想在 x 轴上创建一个带有索引的散点图,只使用熊猫数据框
df.plot.scatter(x = df.index, y = df.value)
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误
Int64Index([0, 1, 2, 3, 4], dtype='int64') not in index
Run Code Online (Sandbox Code Playgroud)
我不想使用
plt.scatter(x = df.index, y = df.value)
Run Code Online (Sandbox Code Playgroud)
如何使用熊猫数据框执行此图
您可以尝试使用:
df.reset_index().plot.scatter(x = 'index', y = 'value')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15385 次 |
最近记录: |