python 2.7 - Efficiently create rolling subsets of dataframe based on month -


i have big dataframe df , trying create list df_list of dataframes contains subset of df based on 2 parameters, viz., size_month , roll_month

dates = pd.date_range('1700-01-01', '2017-07-02') df = pd.dataframe({'date':dates, 'values':np.random.normal(size = len(dates))}) df           date      value 0   1700-01-01  -1.239422 1   1700-01-02  -0.209840 2   1700-01-03   0.146293 3   1700-01-04   1.422454 4   1700-01-05   0.453222 ... 

now if lets size_month=12 , roll_month=2, df_list[0] should following:

            date      value 0     1700-01-01  -1.239422 1     1700-01-02  -0.209840 2     1700-01-03   0.146293 ... 363   1700-12-29   1.562454 364   1700-12-30   0.677222 365   1700-12-31   0.937274 

and df_list[1] should following:

            date      value 0     1700-03-01   0.423422 1     1700-03-02  -0.544840 2     1700-03-03  -0.344293 ... 363   1701-02-26  -1.135334 364   1701-02-27   1.003222 365   1701-02-28   0.443274 

and on. key here df large , brute force approach might not optimal.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -