Plotting period series in matplotlib pyplot

Viewed 12926

I'm trying to plot timeseries revenue data by quarter with matplotlib.pyplot but keep getting an error. Below is my code and the errors The desired behavior is to plot the revenue data by quarter using matplotlib. When I try to do this, I get:

TypeError: Axis must havefreqset to convert to Periods

Is it because timeseries dates expressed as periods cannot be plotted in matplotlib? Below is my code.

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)
2 Answers
Related