Skip to main contentSkip to solution

Consider the following DataFrame: 'Product'

ITNOBRANDPRICEITEM
101WHIRLPOOL20000WASHING MACHINE
109LG1000TELEVISION
120H&M3000BLAZER
111LG7000TELEVISION

Write the python code to display the maximum price of LG TV.

Solution

✅ Correct Option: 4

Product.BRAND=='LG' builds a boolean Series that is True for rows where BRAND is LG. Putting it inside Product[...] keeps only those rows (here the LG rows with prices 1000 and 7000). Calling .max() on this filtered DataFrame gives the maximum of each column, so the PRICE value is 7000, the highest LG price.

To get only the price, write Product[Product.BRAND=='LG'].PRICE.max().


Option 1: Product=='LG' compares the whole DataFrame with a string and does not filter rows by brand.

Option 2: uses = (assignment) instead of == (comparison) inside the brackets, which is a syntax error.

Option 3: BRAND is not defined on its own, and Product[BRAND]='LG'.max() is an assignment, not a filter.

Keyboard Shortcuts

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