Skip to content

Conversation

@lodagro
Copy link
Contributor

@lodagro lodagro 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
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

@wesm
Copy link
Member

wesm 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

@wesm
Copy link
Member

wesm 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
@wesm
Copy link
Member

wesm 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:

wesm@c1307b6

@lodagro lodagro mentioned this pull request Mar 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants