熊猫重新取样OHLC

时间:2016-05-23 03:34:15

标签: 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

1 个答案:

答案 0 :(得分:2)

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

执行dfmxn.dtypes时,如果object看到Bid,则需要按照以下方式进行转换:

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