Ivan
Ivan

Reputation: 7746

Pandas resample OHLC

I have data like this

                             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
...

When I try to

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

I get an error

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

Upvotes: 1

Views: 973

Answers (1)

Jarad
Jarad

Reputation: 18933

I think it means your bid isn't the right datatype.

When you do dfmxn.dtypes, if you see object for the Bid, it needs to be converted like this:

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

Produced this for me:

                         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

Upvotes: 2

Related Questions