本文介绍了从 pandas 数据框绘制累积图表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框,如下所示:
I have a dataframe as follows:
df = pd.DataFrame({'cost_saving': [10, 10, 20, 40, 60, 60], 'id': ['a', 'b', 'c', 'd', 'e', 'f']})如何绘制节省的累积图表?
How can I draw a cumulative chart of the savings?
我正在考虑一个折线图,在x轴上具有项目数量,在y轴上具有总节省量.
I'm thinking of a line chart with number of items on the x-axis, and total savings on the y-axis.
图表应显示节省的大部分资金来自一些项目.
The chart should show that the bulk of the savings come from a few items.
我尝试过:
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')得到我:
更多推荐
从 pandas 数据框绘制累积图表?
发布评论