1>>> d = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19],
2... 'volume': [50, 60, 40, 100, 50, 100, 40, 50]})
3>>> df = pd.DataFrame(d)
4>>> df['week_starting'] = pd.date_range('01/01/2018',
5... periods=8,
6... freq='W')
7>>> df
8 price volume week_starting
90 10 50 2018-01-07
101 11 60 2018-01-14
112 9 40 2018-01-21
123 13 100 2018-01-28
134 14 50 2018-02-04
145 18 100 2018-02-11
156 17 40 2018-02-18
167 19 50 2018-02-25
17# try below code when you want resample on datetime column to other all columns in dataframe
18>>> df.resample('M', on='week_starting').mean()
19 price volume
20week_starting
212018-01-31 10.75 62.5
222018-02-28 17.00 60.0
23
1B business day frequency
2C custom business day frequency (experimental)
3D calendar day frequency
4W weekly frequency
5M month end frequency
6SM semi-month end frequency (15th and end of month)
7BM business month end frequency
8CBM custom business month end frequency
9MS month start frequency
10SMS semi-month start frequency (1st and 15th)
11BMS business month start frequency
12CBMS custom business month start frequency
13Q quarter end frequency
14BQ business quarter endfrequency
15QS quarter start frequency
16BQS business quarter start frequency
17A year end frequency
18BA, BY business year end frequency
19AS, YS year start frequency
20BAS, BYS business year start frequency
21BH business hour frequency
22H hourly frequency
23T, min minutely frequency
24S secondly frequency
25L, ms milliseconds
26U, us microseconds
27N nanoseconds