Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用熊猫来寻找自滚动高点以来的周期数_Python_Pandas - Fatal编程技术网

Python 使用熊猫来寻找自滚动高点以来的周期数

Python 使用熊猫来寻找自滚动高点以来的周期数,python,pandas,Python,Pandas,我在Pandas中使用rolling_max函数: 我如何找到价格这么高以来的周期数?从以下开始: >>> ts A 10 B 10 C -5 D -15 E -9 F -8 G -13 H -9 I -15 J -21 dtype: int64 你可以: >>> rmlag = lambda xs: np.argmax(xs[::-1]) >>> pd.rolling_apply(ts

我在Pandas中使用rolling_max函数:

我如何找到价格这么高以来的周期数?

从以下开始:

>>> ts
A    10
B    10
C    -5
D   -15
E    -9
F    -8
G   -13
H    -9
I   -15
J   -21
dtype: int64
你可以:

>>> rmlag = lambda xs: np.argmax(xs[::-1])
>>> pd.rolling_apply(ts, func=rmlag, window=3, min_periods=0).astype(int)
A    0
B    0
C    1
D    2
E    2
F    0
G    1
H    2
I    1
J    2
dtype: int64
与原始系列和滚动最大值相关:

   value  roll-max  rm-lag
A     10        10       0
B     10        10       0
C     -5        10       1
D    -15        10       2
E     -9        -5       2
F     -8        -8       0
G    -13        -8       1
H     -9        -8       2
I    -15        -9       1
J    -21        -9       2

[10 rows x 3 columns]

你在哪里找到rolling_high功能的?抱歉。我的意思是滚动。我会编辑这个问题。谢谢你写了这么一个简单易懂的解决方案!