0

For example, i have a dataframe with noodles data, it has columns like brand, country, style, stars. The most important ones here are country and style. Country is responsible for country that the noodles were made in, and style is responsible for serving style (bowl, cup, etc). What i want to do, is to find the amount of noodles that used a certain style in each country, and then find the most used one. This is how i did the part of the task:

df = pd.read_csv('data.csv')
res1 = df.groupby(['country', 'style']).count()['brand']
res1

The result of this code looks kinda like this:

Country        Style
Australia      Cup       17
               Pack       5
Bangladesh     Pack       7
Brazil         Cup        2
               Pack       3
Cambodia       Pack       5
Canada         Bowl       8
               Cup       17
               Pack      16

What i actually want to do, is to get the max value in each style group. In my head, result should look kind like this:

Country        Style
Australia      Cup       17
Bangladesh     Pack       7
Brazil         Pack       3
Cambodia       Pack       5
Canada         Cup       17

Also i believe the code should kinda look like this(???), i mean as an idea:

res1.agg_func_to_group('Style', 'max')

Any ideas or suggestions on how to do that? I could give you the data itself, if needed. Thanks in advance for attention

0 Answers0