python - Pandas 重新采样 OHLC

标签 python pandas

我有这样的数据

                             bid
time                             
2016-05-22 21:05:57.651  18.32280
2016-05-22 21:06:58.005  18.32280
2016-05-22 21:17:30.739  18.31820
2016-05-22 21:17:34.121  18.31820
...

当我尝试

df_ohlcMXN = dfmxn.resample('5Min').ohlc()

我收到错误

pandas.core.base.DataError: No numeric types to aggregate

最佳答案

我认为这意味着您的出价数据类型不正确。

当您执行dfmxn.dtypes时,如果您看到Bidobject,则需要像这样进行转换:

dfmxn['Bid'] = dfmxn['Bid'].astype('float64')
dfmxn.resample('5Min').ohlc()

为我制作了这个:

                         Bid                           
                        open     high      low    close
Time                                                   
2016-05-22 21:05:00  18.3228  18.3228  18.3228  18.3228
2016-05-22 21:10:00      NaN      NaN      NaN      NaN
2016-05-22 21:15:00  18.3182  18.3182  18.3182  18.3182

关于python - Pandas 重新采样 OHLC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37382270/

相关文章:

python - more_like_this 多个索引的elasticsearch查询

python - 在 Ubuntu 14.04(64 位)上安装 TensorFlow-0.9.0rc0 在此平台上不受支持

python - 给定以下约束,如何将一些数字连接到另一个数字?

python - 检查某个值在时间范围内是否超过阈值的最佳方法

python - Pandas df 'A' 和 'B 1' 是列名。我如何像 df.A 一样引用 'B 1'?

python - 保存并加载 keras.callbacks.History

python - 当值完全为字符串格式时,如何将 json 转换为 pandas 数据框

python - 在 Plotly Express 中使用 Pandas 索引

python - pandas.isna 和 numpy.isnan 有什么区别?

python - 我可以检查 pandas 列中是否有多个值吗?