I have a Pandas data frame that has 51034 rows and 10 columns. I want to slice this data frame into 158 smaller data frames based on a list that contains the rows to slice.
How is it possible to slice a pandas data frame into smaller data frames?
For example, if I have a data frame with 10 rows and 4 columns:
A B C D
0 1 2 3 4
1 5 6 7 8
2 9 10 11 12
3 13 14 15 16
4 17 18 19 20
5 21 22 23 24
6 25 26 27 28
7 29 30 31 32
8 33 34 35 36
9 37 38 39 40
This example data frame will be sliced every 2 rows to create 5 new smaller data frames:
DataFrame1:
A B C D
0 1 2 3 4
1 5 6 7 8
DataFrame2:
A B C D
0 9 10 11 12
1 13 14 15 16
DataFrame3:
A B C D
0 17 18 19 20
1 21 22 23 24
DataFrame4:
A B C D
0 25 26 27 28
1 29 30 31 32
DataFrame5:
A B C D
0 33 34 35 36
1 37 38 39 40
I am not sure how to use the slice the larger data frame to create the smaller data frames.
Any suggestions on how to accomplish this goal?
Thank you.
Rodrigo