Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

resample ohlc pandas

In [101]: df.resample('1H').agg({'openbid': 'first', 
                                 'highbid': 'max', 
                                 'lowbid': 'min', 
                                 'closebid': 'last'})
Out[101]: 
                      lowbid  highbid  closebid  openbid
ctime                                                   
2015-09-30 23:00:00  1.11687  1.11712   1.11708    1.117
Comment

pandas resample documentation

B         business day frequency
C         custom business day frequency (experimental)
D         calendar day frequency
W         weekly frequency
M         month end frequency
SM        semi-month end frequency (15th and end of month)
BM        business month end frequency
CBM       custom business month end frequency
MS        month start frequency
SMS       semi-month start frequency (1st and 15th)
BMS       business month start frequency
CBMS      custom business month start frequency
Q         quarter end frequency
BQ        business quarter endfrequency
QS        quarter start frequency
BQS       business quarter start frequency
A         year end frequency
BA, BY    business year end frequency
AS, YS    year start frequency
BAS, BYS  business year start frequency
BH        business hour frequency
H         hourly frequency
T, min    minutely frequency
S         secondly frequency
L, ms     milliseconds
U, us     microseconds
N         nanoseconds
Comment

use functions to resample pandas

#We can also use custom functions and apply them when resampling using the .apply(method_name) method
#This is an example used in a downsampling example
def custom_resampler(arraylike):
    return np.sum(arraylike) + 5
data.resample('Q').apply(custom_resampler)
Comment

pd df resample

df2.resample('D', level=0).sum()
Comment

pd df resample

df.resample('M', on='week_starting').mean()
Comment

PREVIOUS NEXT
Code Example
Python :: how to extract dictionary value from string in python 
Python :: formatted string in python 
Python :: python save plot 
Python :: destructuring for dict in python 
Python :: python - How to execute a program or call a system command? 
Python :: python set cookies 
Python :: python __repr__ meaning 
Python :: demonstrating polymorphism in python class 
Python :: anaconda python 3.6 download 
Python :: Access the elements using the [] syntax nested dictionary 
Python :: how to write manual querry in drf 
Python :: openpyxl get row from sheet 
Python :: sklean tfidf 
Python :: pytorch get non diag element 
Python :: how list ul li with python scraping 
Python :: what is the best ide for python 
Python :: python flask rest api 
Python :: dont truncate dataframe jupyter pd display options 
Python :: how to create one list from 2d list python 
Python :: pandas turn column of list into binary 
Python :: phone numbers python 
Python :: unlimited arguments 
Python :: Pillow opencv convert RGB to BRG or RGB to BRG 
Python :: pandas convert string to numpy array 
Python :: python - remove exta space in column 
Python :: download google drive link collab 
Python :: numba for python 
Python :: Print and remove previous line 
Python :: python init dict by list 
Python :: python crosshair overlay 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =