用于遍历DataFrame Python函数的循环

问题描述 投票:0回答:1

我编写了一个从表格的每一列中删除异常值的函数:(我附有表格的照片)

enter image description here

消除异常值的功能是:

def remove_outliers(df_in, col):

    q1 = df_in[col].quantile(0.25)
    q3 = df_in[col].quantile(0.75)
    iqr = q3-q1
    lower_bound = q1-1.5*iqr
    upper_bound = q3+1.5*iqr
    df_out = df_in.loc[(df_in[col] > lower_bound) & (df_in[col] < upper_bound)]
    return df_out

现在,我想进行“ for循环”或任何其他循环,使代码遍历表的每一列,并具有删除异常值并获得没有异常值的新表的功能。

有人可以帮我吗?

谢谢

Muhrez

python loops dataframe for-loop outliers
1个回答
0
投票
如果需要,您确实可以使用for循环,遍历数据帧中的列。
© www.soinside.com 2019 - 2024. All rights reserved.