gpt4 book ai didi

python - python中的变化点检测

转载 作者:太空狗 更新时间:2023-10-30 00:39:25 25 4
gpt4 key购买 nike

我有一个 pandas DataFrame,其中一列包含以下元素:

[2,2.5,3,2,2.6,10,10.3,10,10.1,10.3,10], 

是否有一个 python 函数可以检测到该列表中从 2.6 到 10 的突然变化?我读了一点点R可以做到这一点。 python中有类似的功能吗?

最佳答案

IIUC 你可以使用 pct_change为了找到邻居之间的差异,然后与您的限制(无论它是什么)进行比较:

s = pd.Series([2,2.5,3,2,2.6,10,10.3,10,10.1,10.3,10])

In [105]: s.pct_change()
Out[105]:
0 NaN
1 0.250000
2 0.200000
3 -0.333333
4 0.300000
5 2.846154
6 0.030000
7 -0.029126
8 0.010000
9 0.019802
10 -0.029126
dtype: float64

In [107]: s[s.pct_change() > 1]
Out[107]:
5 10
dtype: float64

In [117]: s[s.pct_change() > 1].index.tolist()
Out[117]: [5]

关于python - python中的变化点检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34992672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com