Reputation: 816
I want to plot a time series count bar plot based on month and day. I have a pandas data frame like this:
date_time
2003-01-01 1
2003-01-05 1
2003-01-06 1
2003-01-07 1
2004-01-01 1
2005-01-01 1
2005-01-05 1
2005-02-01 1
I was trying:
df.groupby(df.index.month).count().plot(kind="bar")
but this only isolates either all of the months or all of the days. It doesn't preserve months and days while removing the year dependence.
Here is an example of the data that would be in the final bar plot:
01-01 3
01-05 2
01-06 1
01-07 1
02-01 1
Counts each instance preserving both month and day while removing the year dependence.
Upvotes: 1
Views: 737
Reputation: 1373
Here you go. A very simple implementation:
df = pd.DataFrame({'date_time': ['2003-01-01','2003-01-05','2003-01-06','2003-01-07','2004-01-01','2005-01-01','2005-01-05','2005-02-01'], ' ': [1,1,1,1,1,1,1,1]})
df = df.set_index('date_time')
df.index = pd.to_datetime(df.index)
df.groupby(df.index.strftime('%m-%d')).count().plot.bar()
Upvotes: 1