0

I have a dataframe containing various dates and a corresponding value for that date. I am attempting to group the data by week and sum the values for the week, for the 15th and 16th there is no data (as expected) so when I group the data and sum the resultant dataframe does not contain weeks 15 and 16.

I would like to produce a dataframe that contain rows 15 and 16 but has a value of 0 in each

Please see code as per image below

Current code and output

Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55

1 Answers1

0
df[df.ExcessCash > 0].groupby('Date').a.count()
     .reindex(df.date.unique()).fillna(0).astype(int)
     .rename('ExcessCashResult').reset_index()

reference: How to keep Zero counts for pandas groupby count for 2 columns dataframe?

Piotr Żak
  • 2,046
  • 5
  • 18
  • 30