df = pd.DataFrame({'Data':np.random.normal(size=200)})
# example dataset of normally distributed data.
df[np.abs(df.Data-df.Data.mean()) <= (3*df.Data.std())]
# keep only the ones that are within +3 to -3 standard deviations in the column 'Data'.
df[~(np.abs(df.Data-df.Data.mean()) > (3*df.Data.std()))]
# or if you prefer the other way around
对于一个系列,它是相似的:
S = pd.Series(np.random.normal(size=200))
S[~((S-S.mean()).abs() > 3*S.std())]
对于每个dataframe列,您可以使用:
然后过滤:
如果需要删除上下异常值,请将条件与and语句结合起来:
如果数据帧中有多个列,并且希望删除至少一列中有异常值的所有行,则以下表达式将一次性完成此操作。
说明:
像在
numpy.array
中那样使用boolean
索引对于一个系列,它是相似的:
相关问题 更多 >
编程相关推荐