温温酱
您可以使用 pandas 数据帧的 resample 方法,因为数据帧大多数是带有时间戳的索引。这里有一个例子:import pandas as pdimport numpy as npdates = pd.date_range('1/1/2020', periods=30)df = pd.DataFrame(np.random.randn(30,2), index=dates, columns=['X','Y'])df.head()lbl = 'right' # set the label of the window index to the value of the rightw = '3d'threshold = 1 # here goes your threshold for flagging the ration of standard deviation and meanx=df.resample(w, label=lbl).std()['X'] / df.resample(w, label=lbl).mean()['X'] > thresholdy=df.resample(w, label=lbl).std()['Y'] / df.resample(w, label=lbl).mean()['Y'] > thresholdDF2 = pd.concat([x,y], axis=1)