我正在使用来自 yfinance 的数据,它返回一个熊猫数据框。
Volume
Datetime
2021-09-13 09:30:00-04:00 951104
2021-09-13 09:35:00-04:00 408357
2021-09-13 09:40:00-04:00 498055
2021-09-13 09:45:00-04:00 466363
2021-09-13 09:50:00-04:00 315385
2021-12-06 15:35:00-05:00 200748
2021-12-06 15:40:00-05:00 336136
2021-12-06 15:45:00-05:00 473106
2021-12-06 15:50:00-05:00 705082
2021-12-06 15:55:00-05:00 1249763
数据框中有 5 分钟的日内间隔。我想重新采样到每日数据并获得当天最大音量的 idxmax。
df.resample("B")["Volume"].idxmax()
返回错误:
ValueError: attempt to get argmax of an empty sequence
我使用 B(business-days) 作为重采样周期,所以不应该有任何空序列。
我应该说 .max() 工作正常。
同样使用另一个问题中建议的 .agg 会返回错误:
df["Volume"].resample("B").agg(lambda x : np.nan if x.count() == 0 else x.idxmax())
错误:
IndexError: index 77 is out of bounds for axis 0 with size 0