我希望根据groupby和sum创建的汇总数据,随着时间的推移制作堆积区域图。
groupby和sum部分正确地对我想要的数据进行分组和求和,但似乎结果格式在绘制它时是无意义的。
我不确定从哪里开始:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.DataFrame({'invoice':[1,2,3,4,5,6],'year':[2016,2016,2017,2017,2017,2017],'part':['widget','wonka','widget','wonka','wonka','wonka'],'dollars':[10,20,30,10,10,10]})
#drop the invoice number from the data since we don't need it
df=df[['dollars','part','year']]
#group by year and part, and add them up
df=df.groupby(['year','part']).sum()
#plotting this is nonsense:
df.plot.area()
plt.show()