0

I am looking at the below csv file :

enter image description here

We have the question :

Display the mean of the variable gre by group of admitted/not admitted students, using the combination of groupby and mean methods.

I would write :

df['gre'].mean(df.groupby('admit')) 

But the correct answer is :

df[['gre', 'admit']].groupby('admit').mean()

Why do we write before we call the groupby method both columns gre and admit ?

evinda
  • 101

1 Answers1

0

By writing both columns before calling the groupby method, you are telling the groupby function to group the data by the admit column and then perform the mean calculation on the gre column. This will provide the mean of the gre column grouped by the admit column.

Shubham Panchal
  • 2,230
  • 10
  • 21