Resampling Minute data


Question

I have minute based OHLCV data for the opening range/first hour (9:30-10:30 AM EST). I'm looking to resample this data so I can get one 60-minute value and then calculate the range.

When I call the dataframe.resample() function on the data I get two rows and the initial row starts at 9:00 AM. I'm looking to get only one row which starts at 9:30 AM.

Note: the initial data begins at 9:30.

enter image description here

Edit: Adding code:

# Extract data for regular trading hours (rth) from the 24 hour data set
rth = data.between_time(start_time = '09:30:00', end_time = '16:15:00', include_end = False)

# Extract data for extended trading hours (eth) from the 24 hour data set
eth = data.between_time(start_time = '16:30:00', end_time = '09:30:00', include_end = False)

# Extract data for initial balance (rth) from the 24 hour data set
initial_balance = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end =      False)

Got stuck tried to separate the opening range by individual date and get the Initial Balance

conversion = {'Open' : 'first', 'High' : 'max', 'Low' : 'min', 'Close' : 'last', 'Volume' : 'sum'}
sample = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end = False)
sample = sample.ix['2007-05-07']
sample.tail()

sample.resample('60Min', how = conversion) 

By default resample starts at the beggining of the hour. I would like it to start from where the data starts.

1
22
3/10/2019 7:56:14 PM

Accepted Answer

You can use the base argument of resample:

sample.resample('60Min', how=conversion, base=30)

From the above docs-link:

base : int, default 0
    For frequencies that evenly subdivide 1 day, the “origin” of the aggregated intervals.
    For example, for ‘5min’ frequency, base could range from 0 through 4. Defaults to 0

23
2/13/2013 7:10:13 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon