Consider the following DataFrame: 'Product'
ITNO BRAND PRICE ITEM 101 WHIRLPOOL 20000 WASHING MACHINE 109 LG 1000 TELEVISION 120 H&M 3000 BLAZER 111 LG 7000 TELEVISION
Write the python code to display the maximum price of LG TV.
Consider the following DataFrame: 'Product'
| ITNO | BRAND | PRICE | ITEM |
|---|---|---|---|
| 101 | WHIRLPOOL | 20000 | WASHING MACHINE |
| 109 | LG | 1000 | TELEVISION |
| 120 | H&M | 3000 | BLAZER |
| 111 | LG | 7000 | TELEVISION |
Write the python code to display the maximum price of LG TV.
Solution
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.
Related questions:
2025: 27 May Shift 2
2025: 16 May Shift 1