Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1. Group by year and month:
- df_year_month_quantity = df_category_date_quantity.assign(yr = df_category_date_quantity['TransactionDate'].dt.year, mnth = df_category_date_quantity['TransactionDate'].dt.month).groupby(['yr', 'mnth']).agg({'Quantity': 'sum'}).reset_index()
- df_year_month_quantity
- #2.Unstack and set index
- unstack_month_quantity_by_year = df_year_month_quantity.set_index(['mnth', 'yr']).unstack(fill_value = 0).reset_index()
- unstack_month_quantity_by_year = unstack_month_quantity_by_year.set_index('mnth')
- unstack_month_quantity_by_year
- #3.Plot
- sns.set(font_scale=1.3)
- unstack_month_quantity_by_year.plot(figsize=(12,15), subplots = True, cmap='viridis', sharex = False, sharey=True,
- linestyle = '--',linewidth=2.5)
- plt.xticks([1,2,3,4,5,6,7,8,9,10,11,12], ha='center')
- plt.yticks([100000,200000,300000,400000,500000,600000,700000,800000])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement