0

let's suppose I have this kind of data frame:

            Count
Trip Date        
2014-01-01   5370
2014-01-02   8374
2014-01-03   1121
2014-01-04   2246
2014-01-05   2626
...           ...
2019-11-26  63410
2019-11-27  51121
2019-11-28  16090
2019-11-29  23095
2019-11-30  26389

How can I get a new df that looks like this:

             Count
Week number        
1             C1
2             C2
3             C3
4             C4
5             C4
...           ...
n-1         C(n-1)
n             Cn

where Ci is a sum of Count for each 7 days?

alladinsane
  • 185
  • 1
  • 11

1 Answers1

1

First you need to set your index to the date.

df.set_index(df["date"],inplace=True)

Then you just do day week or month like this

df.resample('D').sum()
df.resample('M').sum()
df.resample('Y').sum()

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html

Shoopyman
  • 53
  • 5