In a DataFrame 'df', if you want to find the median salary, which of the following method should be used?
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.
Related questions:
2025: 14 May Shift 1
2025: 21 May Shift 1
2026: 29 May Shift 1