Skip to main contentSkip to solution

If you want to find the median age of the employees in a DataFrame 'df_emp', then which pandas method will be used?

Solution

✅ Correct Option: 3

Selecting the column with df_emp['Age'] gives a Series, and the Series method .median() returns the median of its values. So df_emp['Age'].median() gives the median age directly.


Option 1: this computes the median of every column in the DataFrame first and then picks 'Age'. It is wasteful and raises an error if the DataFrame has non-numeric columns such as names.

Option 2: a Series has only one axis, so axis=1 is invalid for it.

Option 4: median() is not a built-in Python function, and the string 'Age] is missing its closing quote, so it is a syntax error.

Keyboard Shortcuts

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