Skip to main contentSkip to solution

Which method is appropriate for computing both the mean and standard deviation of the "Height" column in a DataFrame 'df_students'?

Solution

✅ Correct Option: 4

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']}.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question