Skip to main contentSkip to solution

Which query generates the DataFrame 'df_orders' to show orders with "Quantity" greater than 10 and "Price" less than 50?

Solution

✅ Correct Option: 2

Filtering a DataFrame in pandas uses boolean indexing: df[condition]. To combine two conditions, each one goes in its own brackets and they are joined with & (AND). Option 2 does this, keeping only rows where Quantity is above 10 and Price is below 50.


Option 1: it has no df_orders[ ... ] around the condition, so it only builds a boolean Series (and has an unmatched bracket). It does not filter any rows.

Option 3: the comparison signs are reversed (<10, >50). Also, without brackets, & binds tighter than the comparison operators, so it raises an error.

Option 4: | means OR, so it returns rows meeting either condition, not both.

Always wrap each condition in parentheses when using & or | in pandas.

Keyboard Shortcuts

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