我有一个很大的风速时间序列(pandas 数据帧)(平均 10 分钟),其中包含错误数据(失效传感器)。怎么能自动标记呢。我正在尝试移动平均线。 非常感谢除移动平均线之外的其他一些方法。我附上了下面的示例数据图像。
请您参考如下方法:
有几种方法可以解决这个问题。我将首先传递差异:
%matplotlib inline
import pandas as pd
import numpy as np
np.random.seed(0)
n = 200
y = np.cumsum(np.random.randn(n))
y[100:120] = 2
y[150:160] = 0
ts = pd.Series(y)
ts.diff().plot();
下一步是找出连续零的击打有多长时间。
def getZeroStrikeLen(x):
""" Accept a boolean array only
"""
res = np.diff(np.where(np.concatenate(([x[0]],
x[:-1] != x[1:],
[True])))[0])[::2]
return res
vec = ts.diff().values == 0
out = getZeroStrikeLen(vec)
现在如果 len(out)>0 你可以断定有问题。如果您想更进一步,可以查看this。 .它在 R 中,但在 Python 中复制并不难。
