简体   繁体   English

熊猫系列累积argmax

[英]pandas series cumulative argmax

What is an efficient way to get a series of the cumulative argmax of another series? 什么是获得另一系列的一系列累加argmax的有效方法?

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. 这行得通,但我想知道是否有更合适的方法。

You don't need cumargmax function. 您不需要cumargmax函数。 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. pandas 0.18弃用expanding_apply()模块级别的功能。 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 http://pandas.pydata.org/pandas-docs/stable/computation.html上查看文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM