wesm/pandas — pull request #286 by lodagro (2011-10-25 11:46:37+00:00)
Title: ENH: Adding argmin, argmax to Series and DataFrame.

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
Out[23]:
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
Out[26]:
A B C D E
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)
Out[27]:
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)
Out[28]:
a b 10 E
p q 20 B
x y 30 C
Name: None, Length: 3

What do you think?

Wouter