data = {'Store: ['Shop1', 'Shop'3, 'Shop1', 'Shop2', 'Shop3', 'Shop1', 'Shop2', 'Shop3'],
'Sales(Rs)': [15000, 36000, 45000, 24000, 10000, 43000, 32000, 15000],
'Year': [2016, 2016, 2017, 2017, 2017, 2018, 2018, 2018],
'Profit': [1200, 5600, 3400, 8000, 4800, 3500, 2400, 12000]}
The above DataFrame was created as 'df'. To find the maximum sale for Store 'Shop2', we will use _______.
data = {'Store: ['Shop1', 'Shop'3, 'Shop1', 'Shop2', 'Shop3', 'Shop1', 'Shop2', 'Shop3'],
'Sales(Rs)': [15000, 36000, 45000, 24000, 10000, 43000, 32000, 15000],
'Year': [2016, 2016, 2017, 2017, 2017, 2018, 2018, 2018],
'Profit': [1200, 5600, 3400, 8000, 4800, 3500, 2400, 12000]}
The above DataFrame was created as 'df'. To find the maximum sale for Store 'Shop2', we will use _______.
Solution
df.Store == 'Shop2' creates a boolean Series that is True for the rows of Shop2. Passing it inside df[...] keeps only those rows, so S2df holds only Shop2's records. Then S2df['Sales(Rs)'].max() returns the largest value in the Sales column of those rows.
Option 1: df[Store] == 'Shop2' uses an undefined variable Store, and the comparison is done outside df[...], so it gives a True/False Series, not a filtered DataFrame.
Option 2: Store is not defined on its own. It must be written as df.Store or df['Store'].
Option 3: idmax() does not exist. The real method is idxmax(), and it returns the index label of the maximum, not the maximum value.
Related questions:
2026: 13 May Shift 2
2025: 22 May Shift 1
2025: 30 May Shift 2