【发布时间】:2018-09-16 23:25:29
【问题描述】:
我正在尝试使用以下数据绘制图表。我需要图表 Year vs 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
我的代码:
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] 不在 [列] 中'
我该如何解决这个问题?
【问题讨论】:
标签: python