Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert grouped data with groupby to dataframes

how can i do to convert my grouped data to data frame. Each group in one dataframe? i did this to group my data I wrote:

df = pd.DataFrame({'Animal' : ['Falcon', 'Falcon',
                               'Parrot', 'Parrot'],
                   'Max Speed' : [380., 370., 24., 26.]})
df.groupby('Animal')
like image 434
This Avatar asked Jun 14 '26 12:06

This


1 Answers

Use dict comprehension:

animals = {idx: grp for idx, grp in df.groupby('Animal')}

Access with the 'Animal' as the key like:

animals['Falcon']

[out]

   Animal  Max Speed
0  Falcon      380.0
1  Falcon      370.0
like image 62
Chris Adams Avatar answered Jun 17 '26 01:06

Chris Adams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!