0

I have two columns in a dataframe, one of them are strings (country's) and the other are integers related to each country. How do I ask which country has the biggest value using python pandas?

3
  • 1
    df.groupby('country').max() Commented Jun 30, 2019 at 18:20
  • @anky_91 I'm sorry I didn't make this clear, but actually there are more columns in the dataframe. Commented Jun 30, 2019 at 18:26
  • 1
    Welcome to StackOverflow. Please take the time to read this post on how to provide a great pandas example as well as how to provide a minimal, complete, and verifiable example and revise your question accordingly. Commented Jun 30, 2019 at 18:38

1 Answer 1

1

Setup

df = pd.DataFrame(dict(Num=[*map(int, '352741845')], Country=[*'ABCDEFGHI']))

df

   Num Country
0    3       A
1    5       B
2    2       C
3    7       D
4    4       E
5    1       F
6    8       G
7    4       H
8    5       I

idxmax

df.loc[[df.Num.idxmax()]]

   Num Country
6    8       G

nlargest

df.nlargest(1, columns=['Num'])

   Num Country
6    8       G

sort_values and tail

df.sort_values('Num').tail(1)

   Num Country
6    8       G
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.