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

Speech Recognition using PyAudio and SpeechRecognition Libraries

SHAP (SHapley Additive exPlanations) for variable importance in Python

open multiple sites in python Script using web browser package