Suppose that a DataFrame for car purchases is given as 'df_purchases' having columns "Product" and "Price". Which of the following statements will find the product with the highest price?
A. df_purchases['Product'].max()
B. df_purchases.loc[df_purchases['Price'].idxmax()]
C. df_purchases.sort_values('Price', ascending=False).iloc[0]
D. df_purchases.iloc[df_purchases['Price'].idxmax()]
Suppose that a DataFrame for car purchases is given as 'df_purchases' having columns "Product" and "Price". Which of the following statements will find the product with the highest price?
A. df_purchases['Product'].max()
B. df_purchases.loc[df_purchases['Price'].idxmax()]
C. df_purchases.sort_values('Price', ascending=False).iloc[0]
D. df_purchases.iloc[df_purchases['Price'].idxmax()]
Solution
B returns the row whose label is given by idxmax(), the index label of the highest Price, so loc fetches that row.
C sorts the rows by Price from highest to lowest, and iloc[0] picks the top row, which is the most expensive product.
D works here because idxmax() gives the label of the maximum, and with the default index (0, 1, 2, ...) a label equals its position, so iloc fetches the same row.
Option A: max() on the Product column compares the names as strings and returns the alphabetically last name, ignoring Price completely.
iloc uses integer position while idxmax() returns a label, so D fails if the DataFrame has a custom index; loc in B is always safe.
Related questions:
2026: 18 May Shift 2
2026: 29 May Shift 2