How do you select rows from a DataFrame 'df', where the 'Amount' column is greater than 40000?
How do you select rows from a DataFrame 'df', where the 'Amount' column is greater than 40000?
Solution
✅ Correct Option: 2
Option 2 uses boolean indexing, the standard way to filter rows in pandas. The inner expression builds a Series of True/False values, one per row. Passing it to keeps only the rows where the value is True.
Options 1 and 3: pandas has no methods called select_rows or filter_rows. Also, 'Amount' > 40000 compares a plain string with a number, which raises an error.
Option 4: pandas has no rows() method. Writing the condition inside quotes only works with df.query('Amount > 40000').
Related questions:
2025: 15 May Shift 2
2026: 13 May Shift 2
2026: 21 May Shift 1