[Python] Is my approach to handling outliers and missing values appropriate for correlation...

Discussão em 'Python' iniciado por Stack, Maio 3, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently dealing with a numeric dataset to analyze the relationship between age and ADHD symptoms for example (Externalizing,Conduct_Problems,...).

    Preprocessing Steps Taken: Missing Values: Dropped rows with >6 missing columns. Imputed remaining missing values using: Median for skewed columns (skew > 1 or skew < -1), Mode for columns with <10 unique values, Mean otherwise.

    Outlier Handling: Detected outliers using boxplots and histograms. Replaced outliers (outside 1.5×IQR) with the column’s median. Example code for one variable:

    python

    Q1 = df['SDQ_SDQ_Conduct_Problems'].quantile(0.25)
    Q3 = df['SDQ_SDQ_Conduct_Problems'].quantile(0.75)
    IQR = Q3 - Q1
    lower_bound = Q1 - 1.5 * IQR
    upper_bound = Q3 + 1.5 * IQR
    df['SDQ_SDQ_Conduct_Problems'] = np.where(
    (df['SDQ_SDQ_Conduct_Problems'] < lower_bound) |
    (df['SDQ_SDQ_Conduct_Problems'] > upper_bound),
    df['SDQ_SDQ_Conduct_Problems'].median(),
    df['SDQ_SDQ_Conduct_Problems']
    )


    _ Is my approach right and does anyone have any comments or suggestions on how i can improve the code?

    Continue reading...

Compartilhe esta Página