If you want to find the median age of the employees in a DataFrame 'df_emp', then which pandas method will be used?
If you want to find the median age of the employees in a DataFrame 'df_emp', then which pandas method will be used?
Solution
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.
Related questions:
2025: 3 June Shift 2
2026: 11 May Shift 2
2026: 29 May Shift 1
2025: 16 May Shift 1
2025: 21 May Shift 1