DataFrame:根据条件识别异常值并替换DataFrame中的值

2024-04-19 15:47:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要识别数据帧中的异常值,在我的情况下,这些值高于4*Z-score。“我的数据帧”有许多按日期排序的列(2012-01-01 1:30:00)。你知道吗

this is my data set

这些值遵循时间模式和温度数据,因此我们需要同时评估给定数据与其他数据相比是否存在差异。例如,如果我将下午记录与其他时段的值进行比较,这可能被认为是错误的差异。你知道吗

我试了一些东西只为一个专栏,但没有结果。你知道吗

hours = ['00:00','01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00','23:59']

df = pd.read_excel(file)
df.set_index('Date',inplace=True)

for i in range(24):

    df.loc[df[np.abs((df['column1'].between_time(hours[i],hours[i+1]) - df['column1'].between_time(hours[i],hours[i+1]).mean())/df['column1'].between_time(hours[i],hours[i+1]).std()) > 4], 'column1']='outlier'

Tags: 数据dftime排序记录时间模式情况