2024-10-01 11:38:16 发布
网友
我有一个数据框如下:
df = pd.DataFrame({'cost_saving': [10, 10, 20, 40, 60, 60], 'id': ['a', 'b', 'c', 'd', 'e', 'f']})
我怎样才能画出储蓄的累积图表?
我在想一个折线图,x轴上有项目数,y轴上有总节省。
图表应该显示大部分储蓄来自于一些项目。
我试过:
dftest['cost_saving'].plot(drawstyle='steps')
但它没有绘制累积值。
谢谢你的帮助!
我做到了:
df.set_index('id').cumsum()
得到:
cost_saving id a 10 b 20 c 40 d 80 e 140 f 200
这:
df.reset_index().plot.line(df.cost_saving.cumsum(), 'index', drawstyle='steps')
让我明白:
我做到了:
得到:
这:
让我明白:
相关问题 更多 >
编程相关推荐