我已将每日数据转换为烛台图表的每周数据。这是我的代码:
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']]
但是,我收到以下警告:
FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...)..apply(<func>)
我试图这样做但是无法正确执行,导致错误。如何更改它,以便它符合警告?