Python Forum

Full Version: 2 Different Sorts in a Dataframe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone!

I have a dataframe with 2 columns (A,B) and 3 rows.

A B

1 X
2 Y
3 Z

I am using this code right now

variable = df["A"].sort_values(ascending=True).values[-1]
To assign the current highest value of A to my variable.

How would I make it so, when it assigns the highest value to "variable", that is only checks for X in column B instead of checking every row?

So I would like the code to instead assign 1 to variable, since the highest number for X is 1

Any ideas?
Got it right here, if anyone is interested in also learning!

https://datatofish.com/select-rows-pandas-dataframe/

Angel