Which method is appropriate for computing both the mean and standard deviation of the "Height" column in a DataFrame 'df_students'?
Which method is appropriate for computing both the mean and standard deviation of the "Height" column in a DataFrame 'df_students'?
Solution
df_students['Height'] selects the column as a Series. Series.aggregate() (or agg()) accepts a list of function names and applies each one, so ['mean', 'std'] returns both the mean and the standard deviation in a single result.
Option 1: mean() returns a single number, and a number has no std() method, so this raises an error.
Option 2: apply() takes a function, not a list of names, and it works on the whole DataFrame rather than just "Height".
Option 3: agg() takes one dictionary, and the second dictionary here is read as another argument, not as a second function. The correct form is {'Height': ['mean', 'std']}.
Related questions:
2026: 11 May Shift 2
2026: 24 May Shift 1