Python Forum
Monthly sales, standard deviation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Monthly sales, standard deviation
#1
Hi, there. I am back to the knowledge well!

Using pandas I have a dataframe with Date, Item#, Qty and 12 months of data. I want to do a std dev calc to understand the monthly variability for each Item#.

The problem is for many Item#'s the sales are very sporadic: I may only sell Item XYZ in Feb and Mar, and zero the rest of the months of the year.

I am using this code to do the heavy lifting:

df.groupby('Item#').resample('M').sum()

For some Item#'s it is forcing zeros into the empty months (GOOD!), but in many cases it is just showing, say, two months of data, instead of 12, which then makes the std dev calculation incorrect.

Can someone help me understand why this erractic behaviour of the resample method? How can I workaround this problem?

Many thanks in advance for your help!
Reply


Messages In This Thread
Monthly sales, standard deviation - by Lyle - Jul-31-2020, 04:35 PM
RE: Monthly sales, standard deviation - by Lyle - Aug-07-2020, 05:10 PM
RE: Monthly sales, standard deviation - by Lyle - Aug-07-2020, 10:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Resample from monthly to weekly works, but not vice versa JaneTan 0 1,213 Dec-14-2022, 12:58 AM
Last Post: JaneTan
  Winsorized Mean and Standard Deviation Wheeliam 0 2,532 Jul-11-2020, 05:27 PM
Last Post: Wheeliam
  standard library modules chpyel 4 4,090 May-10-2020, 02:58 PM
Last Post: snippsat
  plot multiple employee sales data in a single graph pitanshu 0 2,446 Oct-24-2019, 01:56 PM
Last Post: pitanshu
  Is there a standard for autocommit In PEP 249 zatlas1 10 7,745 Feb-06-2019, 04:56 PM
Last Post: buran
  Graphics and standard deviation rocioaraneda 3 3,863 Jan-09-2019, 10:53 PM
Last Post: micseydel
  How to calculate variance(standard deviation) by column SriRajesh 2 3,649 Dec-27-2018, 12:35 PM
Last Post: SriRajesh
  standard data types rombertus 3 102,816 Dec-23-2018, 08:52 PM
Last Post: rombertus
  Create a monthly mean column in multiple years fyec 1 5,106 Jun-21-2018, 03:57 AM
Last Post: scidam
  Standard library code BerryK 2 4,899 Apr-29-2017, 10:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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