5.6 groupby
Note
Click here to download the full example code or to run this example in your browser via Binder
5.6 groupby#
This lesson shows the usage of groupby in pandas
Important
This lesson is still under development.
The material in this lesson is mostly inspired from pandas documentation for groupby and realpython However, it has been modified for easy of practice and understanding.
import pandas as pd
print(pd.__version__)
1.5.3
df = pd.DataFrame( {'a':['A','A','B','B','B','C'], 'b':[1,2,5,5,4,6]})
df
df.groupby('a')['b'].apply(list)
a
A [1, 2]
B [5, 5, 4]
C [6]
Name: b, dtype: object
df.groupby('a')['b'].apply(list).reset_index(name='new')
Total running time of the script: ( 0 minutes 0.008 seconds)