Reputation: 294258
What is an efficient way to get a series of the cumulative argmax of another series?
The way I figured is
import pandas as pd
def cumargmax(series):
return pd.expanding_apply(series, lambda x: x.argmax())
This works, but I'm wondering if there is a more appropriate way.
Upvotes: 0
Views: 323
Reputation: 7358
You don't need cumargmax function. Instead, you could do this in one line,
pd.expanding_apply(series, lambda x: x.argmax())
pandas 0.18 is deprecating expanding_apply() module level funtions. They are replacing with the following method call,
series.expanding().apply(lambda x: x.argmax())
Check out documentation at http://pandas.pydata.org/pandas-docs/stable/computation.html
Upvotes: 1