1

I have converted daily data to weekly data for my candlestick_ohlc chart. This is my code:

df['Date'] = pd.to_datetime(df['Date'])
df.set_index('Date', inplace=True)
df.sort_index(inplace=True)



def take_first(array_like):
    return array_like[0]

def take_last(array_like):
    return array_like[-1]

output = df.resample('W',                                 # Weekly resample
                    how={'Date2': take_first,
                        'Open': take_first, 
                         'High': 'max',
                         'Low': 'min',
                         'Close': take_last,
                         'Volume': 'sum'}, 
                    loffset=pd.offsets.timedelta(days=-6))  # to put the labels to Monday

df = output[['Date2','Open', 'High', 'Low', 'Close', 'Volume']]

However, I am getting the following warning:

FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...)..apply(<func>)

I attempted doing so but am not being able to do it correctly, resulting in an error. How can I change it, so that it is in accordance with the warning?

zcdp
  • 79
  • 10
  • [bchip](https://stackoverflow.com/users/14700156) posted an [Answer](https://stackoverflow.com/a/66312353) saying "For anyone finding this later on a relevant answer can be found here [converting daily stock data to weekly-based via pandas in Python](https://stackoverflow.com/questions/34597926/converting-daily-stock-data-to-weekly-based-via-pandas-in-python#34598511)" – Scratte Feb 22 '21 at 19:52

0 Answers0