我正在尝试使用以下数据绘制图表。我需要图表 Year 与 Txns
原始数据即代码中的dataset1=
WeekDay Day Month Year Time Txns
1 5 1 2015 3 1
1 5 1 2015 4 4
1 5 1 2015 5 1
1 5 1 2015 7 2
这是代码中group by和sum之后的数据,即plot=
Index Txns
(2014, 12) 5786
(2015, 1) 70828
(2015, 2) 63228
(2015, 3) 74320
my code:
plot = dataset1.groupby(['Year', 'Month'])['Txns'].sum()
plot_df = plot.unstack('Month').loc[:, 'Txns']
plot_df.index = pd.PeriodIndex(plot_df.index.tolist(), freq='2015')
plot_df.plot()
我每次都会收到此错误:
KeyError:“标签 [Txns] 不在 [列] 中”
我怎样才能解决这个问题?
为什么不只是data.groupby('Year').Txns.sum()
如果你想按年份和总和分组Txns
?
and .plot()
如果你想绘制它:
或年度线路:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)