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 get value from set in python 
Python :: pandas apply output multiple columns 
Python :: python print error output 
Python :: python get dictionary keys as list 
Python :: numpy get diagonal matrix from matrix 
Python :: lower case of string 
Python :: python run powershell command and get output 
Python :: python convert two dimensional list to one dimensional 
Python :: markers seaborn 
Python :: pandas loc condition 
Python :: async python 
Python :: how to reset username and password in django admin 
Python :: cv2.copyMakeBorder 
Python :: find all occurrences of an element in a list python 
Python :: python elapsed time module 
Python :: python possible combinations 
Python :: if settings.debug 
Python :: python program to print the fibonacci sequence 
Python :: how to change int to four decimal places in python 
Python :: python dict remove duplicates where name are not the same 
Python :: how to copy file from local to sftp using python 
Python :: python cut string to length 
Python :: python for loop with step 
Python :: ast python 
Python :: how to find the path of a python module 
Python :: python tkinter code example 
Python :: compare two dates python 
Python :: Set symmetric Using Python Set symmetric_difference() Method 
Python :: python png library 
Python :: beautifulsoup usage 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =