2

my version of pandas is 1.1.3, and I'm trying to run code obtained from the accepted answer to this question but

offset = pd.offsets.timedelta(days=-6)

gives the error mentioned in my title, timedelta has been imported but no luck. How can I get this to run properly?

1 Answers1

3

Because there is warning:

FutureWarning: 'loffset' in .resample() and in Grouper() is deprecated.

You can change solution with subtract 6 days after resample:

from pandas.tseries.frequencies import to_offset

df = df.resample('W').apply(logic)
df.index -= to_offset("6D")
#alternative
#df.index = df.index - to_offset("6D")

print (df)
                 Open       High        Low      Close   Volume
Date                                                           
2010-01-04  38.660000  40.700001  38.509998  40.290001  5925600
2010-01-11  40.209999  40.970001  39.279999  40.450001  6234600
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • 1
    first I had to change pd.offsets.timedelta to pd.timedelta before getting the warning. Solution works thank you! –  Aug 26 '21 at 07:17