Skip to main contentSkip to solution

In a DataFrame 'df', if you want to find the median salary, which of the following method should be used?

Solution

✅ Correct Option: 3

df['Salary'] selects the Salary column as a Series, and calling .median() on it returns the median of that column.


Option 1: the . before ['Salary'] is a syntax error. df.median()['Salary'] would work, but it computes the median of every numeric column first.

Option 2: a Series has only axis 0, so axis=1 raises an error.

Option 4: the first argument of df.median() is axis, not a column name, so passing ['Salary'] is invalid.

Keyboard Shortcuts

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