Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get max value and name from a Pandas series?

Tags:

python

pandas

Say I have a series like the one below:

mySeries = pd.Series([1,2,3],['c','b','a'])

How do I go about getting the max value along with the name associated with it in a single line? In this case: a: 3

I can get the max value with: mySeries.max(), the name of the max value with mySeries.idxmax(axis=1) but I can't figure out how to get both of those values with one line. Suggestions?

like image 208
Abe Miessler Avatar asked Oct 05 '17 03:10

Abe Miessler


1 Answers

pd.Series.nlargest

mySeries.nlargest(1)

a    3
dtype: int64
like image 64
piRSquared Avatar answered Sep 17 '22 22:09

piRSquared