Python Forum
How to groupby Months showing average order value - Pandas & matplotlib - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to groupby Months showing average order value - Pandas & matplotlib (/thread-30421.html)



How to groupby Months showing average order value - Pandas & matplotlib - Rwood90 - Oct-20-2020

hello,
I am working with some data and would like to show the average order value (aov) for the different months. When I look at total revenue in the set period (£839736) and divide it by the total amount of transactions in that period (1232), it shows an average order value of £681. Is there a way this can be separated into individual months? As I know that the Average Order Value will be different for each month.
Code is below: the dataframe is stored in a variable called ikdf.
months = [month for month , df in ikdf.groupby('Month')]

invs = ikdf.groupby('Invoice ID').sum()
total_invs = len(invs)
rev = ikdf['Total Value'].sum()
aov = rev / total_invs


plt.bar(months, aov)
plt.xticks
plt.ylabel('AOV per month')
plt.xlabel('Months')
plt.show()[/inline][/python]

Sorry I cannot embed the output as an image into this box.
The output shows an average order value of £681 for all months.

Is there a way that I can separate this to show the different Average Order Values and how it varies each month?