无法将每日数据重新采样为每周数据并且无法应用逻辑
Failing to resample daily data to weekly and can't apply logic
我正在尝试使用以下代码将每日 OHLCV 数据转换为每周数据:
#resample so that Open is the first monday price, High and low are the weeks min and max and close is the last sunday price and volume is the sum (can be customized - pandas docs)
logic = {'Open' : 'first',
'High' : 'max',
'Low' : 'min',
'Close' : 'last',
'Volume': 'sum'}
from pandas.tseries.frequencies import to_offset
BTC.resample('W').apply(logic)
BTC.index -= to_offset("6D")
BTC.head()
这会打印一个数据框,它只是原始的每日数据,日期索引偏移 6 天 - 应用了 none 逻辑。我怎样才能成功地重新采样到每周并应用逻辑?
您错过了一项作业:
BTC = BTC.resample('W').apply(logic) # <-- here
BTC.index -= to_offset("6D")
BTC.head()
分析财务数据时的另一个建议:使用 Adjusted Close
列而不是 Close
列来计算拆分、股息等
我正在尝试使用以下代码将每日 OHLCV 数据转换为每周数据:
#resample so that Open is the first monday price, High and low are the weeks min and max and close is the last sunday price and volume is the sum (can be customized - pandas docs)
logic = {'Open' : 'first',
'High' : 'max',
'Low' : 'min',
'Close' : 'last',
'Volume': 'sum'}
from pandas.tseries.frequencies import to_offset
BTC.resample('W').apply(logic)
BTC.index -= to_offset("6D")
BTC.head()
这会打印一个数据框,它只是原始的每日数据,日期索引偏移 6 天 - 应用了 none 逻辑。我怎样才能成功地重新采样到每周并应用逻辑?
您错过了一项作业:
BTC = BTC.resample('W').apply(logic) # <-- here
BTC.index -= to_offset("6D")
BTC.head()
分析财务数据时的另一个建议:使用 Adjusted Close
列而不是 Close
列来计算拆分、股息等