Joseph arasta
Joseph arasta

Reputation: 161

How to resample 1 minute data to 10 minute data?

import pandas as pd

file = pd.read_csv('D:\\Ayush\\Data\\Bank nifty Data\\Testing.csv')

file['Date_time'] = file['Date/Time'] + ' ' + file['Time']
file['Date_time'] = pd.to_datetime(file['Date_time'])
file.drop(columns=['Date/Time','Time'],inplace=True)
file['Date'] = file['Date_time'].dt.date
file['Date_time'].set_index(inplace=True)

ohlc_dict = {
            'open':'first',
            'high':'max',
            'low':'min',
            'close':'last',
            'volume':'sum'
            }
a = file.resample('10min',how=ohlc_dict)

The above is the complete code. I have gone through other posts too regarding resampling, but I just could not get through it.
After I run this code, I get an error:

TypeError: resample() got an unexpected keyword argument 'how'

I changed this to the code

file.resample('10min').apply(ohlc_dict)

now I am getting this error

SpecificationError: nested renamer is not supported

Upvotes: 1

Views: 3200

Answers (2)

prashant
prashant

Reputation: 219

following code can be used to resample '1min' data to '10min' data :-

df = pd.DataFrame()
df['open'] = file.open.resample('10min').first()
df['high'] = file.high.resample('10min').max()
df['low'] = file.low.resample('10min').min()
df['close'] = file.close.resample('10min').last()

Upvotes: 1

Andy Wong
Andy Wong

Reputation: 4414

file.high.resample('10min').max()

I will suggest you to do the resample 1 by 1.

https://benalexkeen.com/resampling-time-series-data-with-pandas/

Upvotes: 1

Related Questions