Search code examples
python-3.xpandasresampling

Resampling data in pandas on specific day of week


I have this other dataframe:

data.resample('W').mean()
Out[4]: 
                    High           Low  ...    Volume     Adj Close
Date                                    ...                        
2007-09-23   4691.279980   4593.900000  ...       0.0   4671.659961
2007-09-30   4989.619922   4916.960059  ...       0.0   4966.690039
2007-10-07   5208.074951   5081.512451  ...       0.0   5168.562500
2007-10-14   5426.950000   5236.140039  ...       0.0   5361.380078
2007-10-21   5635.509961   5295.409961  ...       0.0   5492.809863
                 ...           ...  ...       ...           ...
2020-06-28  10440.630078  10273.409961  ...  775100.0  10351.880078
2020-07-05  10483.109961  10367.749805  ...  565380.0  10440.719922
2020-07-12  10825.859961  10701.469922  ...  637060.0  10770.110156
2020-07-19  10833.180078  10648.310156  ...  634740.0  10733.980078
2020-07-26  11170.524902  11056.487549  ...  522850.0  11132.099854

[671 rows x 6 columns]

It is resampled over Sunday. How can i resample this dataframe so it is resampled over Monday instead of the default of it being resampled on Sunday?


Solution

  • You can use W-Mon:

    data.resample('W-Mon').mean()