How to shift daily data data frame column by a calendar month?

Viewed 82

I have a df daily data pandas.DataFrame that looks as follows:

                    Col2                               Col2 
Date                                                              
1964-01-01          57.387097                          4.322581   
1964-01-02          57.274194                          4.322581   
1964-01-03          57.161290                          4.322581   
1964-01-04          57.048387                          4.322581   
1964-01-05          56.935484                          4.322581   
...                       ...                               ...   
2020-03-11          50.313333                          3.200000   
2020-03-12          50.260000                          3.200000   
2020-03-13          50.206667                          3.200000   
2020-03-14          50.153333                          3.200000   
2020-03-15          50.100000                          3.200000  

I'd like to negative-shift or lag the first column by a calendar month consistently so I end up with the last month to NaN. If I shift by -22 average business days per month I'll end up of course with grossly misaligned data.

I've tried multiple variations of the following but it doesn't work:

df['Col1'] = df['Col1'].shift(-1, freq='M') 
df['Col1'] = df['Col1'].shift(-1, freq=DateOffset(months=1))

The first variation works but turns my data frame into monthly data and that's not what I intended. Any ideas?

0 Answers
Related