1

I currently have a data frame dfB which looks like follows

enter image description here

My goal is to now plot the number of orders per week. I am not sure of how to go about grouping my column most_recent_order_date per week,though. How can I do this?

ai.jennetta
  • 1,076
  • 2
  • 10
  • 25
  • 2
    Possible duplicate of [group by week in pandas](https://stackoverflow.com/questions/45281297/group-by-week-in-pandas) – roganjosh Sep 07 '18 at 15:15
  • @roganjosh I did not think It was a duplicate since they are doing something slightly different, and I don't know how to apply their answer to my problem. – ai.jennetta Sep 07 '18 at 15:21
  • Because I do not have a column like 'Name' that I want to group by. When I try just putting most_recent_order_date as my group by, it doesn't work: dfB.groupby('most_recent_order_date').resample('W-Mon', on='most_recent_order_date').sum().reset_index().sort_values(by='most_recent_order_date') – ai.jennetta Sep 07 '18 at 15:28
  • So you don't need to do a `grouby`, just a resample – roganjosh Sep 07 '18 at 15:32
  • 1
    Please consider dropping the images and replacing with a [good, reproducible pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). Then we can get straight to solving the problem rather than building examples from scratch. – roganjosh Sep 07 '18 at 15:34

1 Answers1

1

Convert the date column to datetime dtype if you haven't already.

dfB['most_recent_order_date'] = pd.to_datetime(dfB.most_recent_order_date)

Then use resample

dfB.resample('W-Mon', on='most_recent_order_date').sum()
Abhi
  • 4,068
  • 1
  • 16
  • 29