I have a large time-series dataframe. I would like to write a function that will arbitrarily split this large dataframe into N contiguous subperiods as new dataframes so that analysis may easily be done on each smaller dataframe.
I have this line of code that splits the large dataframe into even subperiods. I need a function that will output these split dataframes.
np.array_split(df, n) #n = arbitrary amount of new dataframes
I would like each new dataframe to be labeled as 1,2,3,4, etc. for each subperiod that it represents. So returning N number of dataframes that are all labeled according to their temporal nature of the initial large dataframe.
df before the function applied
1 43.91 -0.041619
2 43.39 0.011913
3 45.56 -0.048801
4 45.43 0.002857
5 45.33 0.002204
6 45.68 -0.007692
7 46.37 -0.014992
8 48.04 -0.035381
9 48.38 -0.007053
3 new df's after function split applied
df1
1 43.91 -0.041619
2 43.39 0.011913
3 45.56 -0.048801
df2
4 45.43 0.002857
5 45.33 0.002204
6 45.68 -0.007692
df3
7 46.37 -0.014992
8 48.04 -0.035381
9 48.38 -0.007053
Please let me know if clarification is needed for any aspects. Thanks for the time!