Skip to main contentSkip to solution

StoreYearTotal_SalesTotal_profit
0S1201615000015000
1S4201640000040000
2S3201645000045000
3S1201735000035000
4S2201612000012000
5S4201745000045000
6S3201750000050000

In the DataFrame 'df' given above, there is a need for maximum sale for store 'S1' in any year. Which query will be appropriate for the problem?

(A) max_sales = df[df.Store == 'S1']

max_sales['Total_Sales'].max()

(B) max_sales = df[df['Store'] == 'S1']

max_sales['Total_Sales'].max()

(C) max_sales = df[df.Store == 'S1']

max_sales.df['Total_Sales'].max()

(D) max_sales = df[df['Store'] == 'S1']

max_sales.df['Total_Sales'].max()

Solution

✅ Correct Option: 2

Filtering with a Boolean condition, df[df.Store == 'S1'] or df[df['Store'] == 'S1'], keeps only the rows for store S1. Taking ['Total_Sales'].max() on that filtered DataFrame then gives the highest sales for S1, which is 350000350000.

Both (A) and (B) do this. Dot notation (df.Store) and bracket notation (df['Store']) select the same column.


(C) and (D): max_sales is already a DataFrame, so max_sales.df is not a valid attribute and raises an AttributeError.

Keyboard Shortcuts

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