Groupby with multiple functions and handling multiple index

creating a data-set-

import pandas as pd
a='a'
b='b'
df= pd.DataFrame({'survived':[0,1,1,1,0,1],'class': [a,b,a,b,a,b]})

have a look of data-set-



group by based on class -

grouped_data= df.groupby(['class']).agg({'survived':['max', 'sum']})


have alook at grouped data , it has got multiple index now-




we can delete on of the column index-

grouped_data.columns=grouped_data.columns.get_level_values(1)




Comments

Popular posts from this blog

Automatically open and do some actions on web pages in python using different packages

Explainability in Data Science:- Data, Model & Prediction