0

Let's say I have the following data frame

  a    b 
0 aaa  123
1 bbb  345
2 ccc  678
3 aaa  91011
4 ccc  111213
5 bbb  131415

What I want is to group by the different values of column a, so I execute gb = df.groupby('a') and now my dataframe is:

  a    b 
0 aaa  123
1 aaa  91011
2 bbb  345
3 bbb  131415
2 ccc  678
4 ccc  111213

In the end, I want to have 3 data frames with different values.

For example, the first data frame will be

   a    b 
0 aaa  123
1 aaa  91011

Any ideas?

Also, how to perform when I have thousands of values in column a?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
loutsi1
  • 25
  • 5
  • 1
    how is this different from: https://stackoverflow.com/q/67623126/9840637 ? – anky May 20 '21 at 16:53
  • There's also many answers here https://stackoverflow.com/questions/19790790/splitting-dataframe-into-multiple-dataframes – Leo May 20 '21 at 16:56
  • 1
    `df_dicts = dict(tuple(df.groupby('a')))` Then `df_dict['aaa']` and `df_dict['bbb']` and `df_dict['ccc']`. – Scott Boston May 20 '21 at 17:01

0 Answers0