0

Here is my database: enter image description here

and i would like to have such table:

Year
2010    9925 BABY FOOD
2011    8829 BEVERAGES 
2012    8661 COSMETICS 
2013    9892 COSMETICS
2014    9389 BEVERAGES 
2015    8250 HOUSEHOLD
2016    8867 COSMETICS
2017    8974 HOUSEHOLD

my code is:

df.groupby('Year').max()[['Units Sold','Item Type']]
it returns this:
Units Sold  Item Type
Year        
2010    9925    Personal Care
2011    8829    Vegetables
2012    8661    Vegetables
2013    9892    Personal Care
2014    9389    Personal Care
2015    8250    Personal Care
2016    8867    Vegetables
2017    8974    Snacks

it can return the correct max units sold values by year but the item type is wrong. I've tried many ways but I just can't.

mozway
  • 194,879
  • 13
  • 39
  • 75
Adel Toth
  • 3
  • 2

0 Answers0