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

ENH: Adding argmin, argmax to Series and DataFrame. #286

wants to merge 1 commit into from


Copy link

commented Oct 25, 2011

Hi Wess,

Pull request to let you know that i added argmin and argmax methods to Series and DataFrame.
I also included unit tests. It`s not that much work/code, but anyway an interesting enhancement i think.

some examples:
In [23]: s
a 0.80015881463
b 0.983432892599
c 0.965122593504
d 0.81910825442
e 0.726239458506
Name: None, Length: 5

In [24]: s.argmin()
Out[24]: 'e'

In [25]: s[s.argmax()] == s.max()
Out[25]: True

In [26]: df
one two three
a b 10 -0.6155 1.237 1.371 1.24 -0.7725
p q 20 1.14 -0.3743 0.5251 0.2426 1.81
x y 30 0.6626 2.004 -0.01327 1.587 0.3524

In [27]: df.argmax(axis=0)
A ('p', 'q', 20)
B ('x', 'y', 30)
C ('a', 'b', 10)
D ('x', 'y', 30)
E ('p', 'q', 20)
Name: None, Length: 5

In [28]: df.argmin(axis=1)
a b 10 E
p q 20 B
x y 30 C
Name: None, Length: 3

What do you think?



This comment has been minimized.

Copy link

commented Nov 2, 2011

I need to think about the consequences of changing Series.argmin and Series.argmax to return labels instead of integers as they currently do (since it's a subclass of ndarray). I can think of times where I've relied on this. Otherwise it looks good


This comment has been minimized.

Copy link

commented Nov 14, 2011

This didn't merge cleanly so I did it by hand. Renamed the methods to idxmin and idxmax-- very useful, thanks. Did not do argmin/argmax to avoid overloading the ndarray functions. I don't have strong feelings about the names

@wesm wesm closed this Nov 14, 2011


This comment has been minimized.

Copy link

commented Nov 25, 2011

I made some changes to NA-handling in these functions to be consistent with the other reductions, particularly when skipna=False:


@lodagro lodagro referenced this pull request Mar 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.