我试图用matplotlib.pyplot绘制季度时间序列收入数据,但不断收到错误。以下是我的代码和错误所需的行为是使用matplotlib按季度绘制收入数据。当我尝试这样做,我得到:matplotlib pyplot中的绘图期系列
TypeError: Axis must have
频率set to convert to Periods
是因为表现为周期时间序列日期不能在matplotlib绘制?以下是我的代码。
def parser(x):
return pd.to_datetime(x, format='%m%Y')
tot = pd.read_table('C:/Desktop/data.txt', parse_dates=[2], index_col=[2], date_parser=parser)
tot = tot.dropna()
tot = tot.to_period('Q').reset_index().groupby(['origin', 'date'], as_index=False).agg(sum)
tot.head()
origin date rev
0 KY 2016Q2 1783.16
1 TN 2014Q1 32128.36
2 TN 2014Q2 16801.40
3 TN 2014Q3 33863.39
4 KY 2014Q4 103973.66
plt.plot(tot.date, tot.rev)
问题寻求帮助调试(“为什么不是这个代码的工作?”)必须包括所期望的行为,一个特定的问题或错误,并重现它在问题本身所需要的最短的代码。没有明确问题陈述的问题对其他读者无益。请参阅:如何创建[mcve]。 – ImportanceOfBeingErnest
我已添加其他上下文 – oammon