Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: pandas 0.13 Series argmax/argmin returns index label instead of location (changed from 0.12) #6214

Closed
xdliao opened this issue Feb 1, 2014 · 6 comments

Comments

@xdliao
Copy link

xdliao commented Feb 1, 2014

------------------------ pandas 0.12 --------
In [14]: pd.version
Out[14]: '0.12.0'

In [15]: a=pd.Series(range(3), index=('2','3','4'))

In [16]: a.argmax()
Out[16]: 2

In [17]: a.idxmax()
Out[17]: '4'

------------------------ pandas 0.13 --------
In [2]: pd.version
Out[2]: '0.13.0'

In [3]: a=pd.Series(range(3), index=('2','3','4'))

In [4]: a.argmax()
Out[4]: '4'

In [5]: a.idxmax()
Out[5]: '4'

@jreback
Copy link
Contributor

jreback commented Feb 1, 2014

these are equivalent are aliases to idxmin/idxmax

you could get the index position by doing

s.index.get_loc(s.idxmax()) for example or
np.argmax(s) will also work

prior to 0.13 iIIRC argmin/ max were just pass thrus to numpy

@xdliao
Copy link
Author

xdliao commented Feb 1, 2014

Ok, the new behavior is more intuitive. It's probably good to mentioned the change in 0.13 release note.

@xdliao xdliao closed this as completed Feb 1, 2014
@snth
Copy link
Contributor

snth commented May 14, 2015

Just a quick note on the suggestions above:

np.argmax(s)

will not work to get the index position, however

np.argmax(s.values)

or

s.values.argmax()

does.

@shoyer
Copy link
Member

shoyer commented May 14, 2015

Hmm. Looking back over this, I don't think it was a good idea to change this from the old behavior -- argmax is useful independently of idxmax. Probably too late to change back now, though.

@snth
Copy link
Contributor

snth commented May 15, 2015

I agree. It seems superfluous to have them perform the same function when having argmax do something different would have been useful, as you point out.

@nmooman
Copy link

nmooman commented Nov 16, 2016

In addition to the above no.argmax() Snnth note
with pandas the following would work: np.argmax(data.values) or data.values.argmax()

You could load data file (mixed string and numerical) i.e., csv file using pandas
df=pandas.read_csv('filename1.csv') and do this to get the index:
np.argmax(df.values)
This will work.
If you use np.argmax(df,1) you will get this error like this (due to data has strings):
ValueError: could not convert string to float:

The above error message can be addressed by either uploading data using loadtxt('filename1.csv') in which the filename1.csv does not contain strings or even common delimiters.

On the other hands, df.idxmax would work on pandas loaded data that has strings and numerical. But it does not give you the index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants