Suppose I have a list of tuples with index values:
mapper= [(0,6),(9,13),(17,27)]
And I have a large master_df which I want to split into multiple dfs based on the tuple index values from the list above.
mapper[0][0] is the starting point and mapper[0][1] is the ending point. And i have a list of df names.
df_list= ['df_1','df_2,'df_3']
I have tried the following snippet below trying to populate multiple df based on index values from mapper
for x in range(len(df_list)):
df_list[x] = master_df[mapper[x][0]:mapper[x][1]]
But it is not working out the way I am envisioning. The ideal solution for me would be three separate df splits the master_df based on tuple index value from the list.
Here is an example of what I am trying to accomplish:
master_df:
Name Role Location
0 Gina Assistance NY
1 Jake Officer Brooklyn
2 Boyle Detective 99
3 Scully Assistance NY
4 Diaz Officer Brooklyn
5 Hitchcock Detective 99
6 Amy Assistance NY
7 Terry Officer Brooklyn
8 Holt Detective 99
9 Judy Assistance NY
10 Adrian Officer Brooklyn
mapper = [(0,3),(3,6),(6,11)]
df_list = ['df_1','df_2','df_3']
Seeking outcome
df_1:
Name Role Location
0 Gina Assistance NY
1 Jake Officer Brooklyn
2 Boyle Detective 99
df_2:
Name Role Location
3 Scully Assistance NY
4 Diaz Officer Brooklyn
5 Hitchcock Detective 99
df_3:
Name Role Location
6 Amy Assistance NY
7 Terry Officer Brooklyn
8 Holt Detective 99
9 Judy Assistance NY
10 Adrian Officer Brooklyn
Any help/guidance is appreciated!