Skip to main contentSkip to solution

How do you select rows from a DataFrame 'df' where the 'Salary' column is greater than 50000?

Solution

✅ Correct Option: 2

df['Salary'] > 50000 creates a Boolean Series with True for each row where Salary exceeds 50000 and False otherwise. Passing it inside df[...] keeps only the rows marked True. This is called Boolean indexing.


Option 1: select_rows() is not a pandas method.

Option 3: df["Salary>50000"] looks up a column literally named "Salary>50000" and raises a KeyError. Conditions work only as expressions, not as strings in [].

Option 4: rows() is not a pandas method. Row access is done with loc, iloc or Boolean indexing.

df.query("Salary > 50000") is another valid way to do this, because query() does accept the condition as a string.

Keyboard Shortcuts

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