I have a DataFrame
S C
3 2
3 2
3 2
3 2
3 2
3 2
1 4
1 4
1 4
1 4
1 4
1 4
How can i split the dataframe so that one dataframe has 3 and 2 in S and C and other has 1 and 4 in S and C
Use a comprehension with groupby
df.groupby which provides the grouping you desire._) and the second element is the individual data frame.See:
List Comprehensions
Grouping Stuff
list_of_df = [g for _, g in df.groupby(['NUMBER_OF_TRIPS', 'SERVICE_CLASS'])]
print(*list_of_df, sep='\n\n')
NUMBER_OF_TRIPS SERVICE_CLASS
6 1 4
7 1 4
8 1 4
9 1 4
10 1 4
11 1 4
NUMBER_OF_TRIPS SERVICE_CLASS
0 3 2
1 3 2
2 3 2
3 3 2
4 3 2
5 3 2