我在一個pandas DataFrame中有歷史交易數據,包含價格和交易量欄,由DateTimeIndex索引。用熊貓將貿易數據重採樣到OHLCV中
例如:
>>> print df.tail()
price volume
2014-01-15 14:29:54+00:00 949.975 0.01
2014-01-15 14:29:59+00:00 941.370 0.01
2014-01-15 14:30:17+00:00 949.975 0.01
2014-01-15 14:30:24+00:00 941.370 0.01
2014-01-15 14:30:36+00:00 949.975 0.01
現在,我可以使用df.resample(freq, how={'price': 'ohlc'})
,這是細重新取樣到這一點OHLC數據,但我也想包括音量。
當我嘗試df.resample(freq, how={'price': 'ohlc', 'volume': 'sum'})
,我得到:
ValueError: Shape of passed values is (2,), indices imply (2, 95)
我不太知道什麼是錯我的數據集,或者爲什麼失敗。任何人都可以幫助解決這個問題嗎?非常感激。
問題該內部:https://github.com/pydata/pandas/issues/5946 – Jeff
這似乎使用新的resample API('df.resample('30S')。agg({'price':'ohlc','volume':'sum'})')來解決。 – ayhan