我試圖用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