Python Forum
How to groupby Months showing average order value - Pandas & matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to groupby Months showing average order value - Pandas & matplotlib
#1
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of groupby in a function with Pandas Paulman 0 158 Dec-03-2021, 04:56 PM
Last Post: Paulman
  Illegal instruction? working code for months? korenron 4 2,423 Aug-05-2021, 09:57 AM
Last Post: korenron
  Python Pandas: How do I average ONLY the data >1000 from several columns? JaneTan 0 623 Jul-17-2021, 01:34 PM
Last Post: JaneTan
  How to convert dates in odd format to months lokhtar 2 930 Apr-17-2021, 11:54 AM
Last Post: lokhtar
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 1,206 Mar-11-2021, 10:52 AM
Last Post: buran
  matplotlib x-axis wrong order SchroedingersLion 4 1,689 Feb-23-2021, 05:42 PM
Last Post: nilamo
  python matplotlib groupby okpython 0 487 Feb-08-2021, 11:09 AM
Last Post: okpython
  How to calculate a months' 1st, 4th, 7th day and also 1st again? cananb 3 999 Nov-12-2020, 08:23 AM
Last Post: perfringo
  Matplotlib graphing help (dual y axis, groupby, filter) keml 0 1,261 Feb-07-2020, 02:35 AM
Last Post: keml
  'Age' categorical (years -months -days ) to numeric Smiling29 4 1,470 Oct-17-2019, 05:26 PM
Last Post: Smiling29

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020