0

I got the following dataset with daily data:

            Name  Target  Sales
Datetime
2021-06-01   Amy  9615.4  11800
2021-06-02   Amy  9615.4    0
...
2021-06-30   Amy  9615.4  197.5
2021-07-01   Amy  9259.3  20672
2021-07-02   Amy  9259.3  46523
...
2021-07-31   Amy  9259.3   130
2021-06-01   Zoe  9615.4  33492
2021-06-02   Zoe  9615.4    0
...
2021-06-30   Zoe  9615.4    0
2021-07-01   Zoe  9259.3    0
2021-07-02   Zoe  9259.3    0
...
2021-07-31   Zoe  9259.3    0

And I would like to resample as weekly data. so I performed this code:

sum_dict = {'Target':'sum' , 'Sales': 'sum'}

month_week = month_df.groupby(['Name']).resample('W').apply(sum_dict)
month_week = month_week.reset_index(level=['Name'])

However, I got the result as below which is not desired:

            Name  Target  Sales
Datetime
2021-06-06   Amy  48076.9 120736.4
2021-06-13   Amy  57692.3 183549
...
2021-06-27   Amy  57692.3 1033.8
2021-07-04   Amy  28846.2 867.5
2021-07-04   Amy  27777.8 80755
...
2021-07-25   Amy  55555.5 -538.1
2021-08-01   Amy  55555.5 19094.5
2021-06-06   Zoe  48076.9 33492
2021-06-13   Zoe  57692.3 145898
...
2021-06-27   Zoe  57692.3  258
2021-07-04   Zoe  28846.2   0
2021-07-04   Zoe  27777.8 35292
...
2021-07-25   Zoe  55555.5 54280
2021-08-01   Zoe  55555.5   0

As you can see that both Amy and Zoe weekly data contains the same index after resampling, which is 2021-07-04.

How could I get different indices after resampling? Thanks!

mozway
  • 194,879
  • 13
  • 39
  • 75
Hang
  • 197
  • 1
  • 11
  • @enke How about merging the data with the same index? Apparently, they are in the same week, just starting with different months. It is still the same week, 2021-06-27 to 2021-07-04. While 2021-06-27 to 2021-06-30 are in June and 2021-07-01 to 2021-07-04 are in July. – Hang Feb 07 '22 at 03:55
  • Combine the 2 rows with same indices into 1 row – Hang Feb 07 '22 at 06:50
  • I would like to sum it – Hang Feb 07 '22 at 07:23
  • It turns out, I cannot reproduce your problem. When I run your code, it gives the outcome you expect. –  Feb 07 '22 at 09:05
  • Do you mean you don't get the equivalent indices? – Hang Feb 07 '22 at 09:28
  • no I don't get duplicate weeks. –  Feb 07 '22 at 09:30

0 Answers0