0

I have pandas data frame as below-

df = pd.DataFrame({'key':['X','X','Y','Y','Z'], 'X':np.arange(5), 'Y': [3,4,5,6,7]})

I want to derive mean for the columns 'X' and 'Y', grouped according to the column 'key'

tried this-

df = df[['X','Y']].mean(axis=1) #but unable to group by 'key'

expected output-

key   X    Y
X    1.1  1.1
Y    2.2  2.2
Z    3.3  3.3

0 Answers0