0 votes
1 view
in Data Science by (17.6k points)

I've got a dataframe with a multi index of Year and Month like the following

Year   Month  Value 

1992     1    3

         2     5

         3     8

        …….    …….

1993    1      2

I'm trying to select the maximum Value for each year and put that in a DF like this:

Year     Max

1992       5

1993       2

          ……

There's not much info on multi-indexes, should I simply do a group by and apply or something similar to make it more simple?

If you wish to learn more about how to use python for data science, then go through this data science python course by Intellipaat for more insights.

1 Answer

0 votes
by (38.2k points)

You can simply use max function for your solution:

#bernie's sample data

df = df.max(level=0)

print (df)

Caps      0    

A     1.131616

B     2.010710

If you want to learn data science in-depth then enroll for best data science training.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...