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?