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)
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-
grouped_data.columns=grouped_data.columns.get_level_values(1)
Comments
Post a Comment