【发布时间】:2017-05-21 18:32:33
【问题描述】:
我正在尝试使用 matplotlib.pyplot 按季度绘制时间序列收入数据,但一直出现错误。下面是我的代码和错误所需的行为是使用 matplotlib 按季度绘制收入数据。当我尝试这样做时,我得到:
TypeError: Axis must havefreqset 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)
【问题讨论】:
-
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:如何创建minimal reproducible example。
-
我添加了额外的上下文
标签: pandas matplotlib timeserieschart