I have a large data set of regions, I want to split the datframe into multiple dataframes based on the list of regions.
Example:
regions val1 val2
A 1 2
A 1 2
B 1 2
C 1 2
D 1 2
E 1 2
A 1 2
I want to split the above dataframe by grouping (A,E), (B,C,D)
DF1:
regions val1 val2
A 1 2
A 1 2
E 1 2
A 1 2
DF2:
B 1 2
C 1 2
D 1 2
I tried this by manually specifying df[(df['regions'] == 'A') | (df['regions'] == 'E')]. I want to avoid manually specifying these regions codes while creating the dataframes. I'm quite new to pandas. Is there anyway to do it?