CardiovascularDisease/CVD/preprocessor.py
def cleanup(df: pd.DataFrame):
    """
    - Change "Age" from days to years.
    - Make "Gender" values start from 0.
    - Normalize data by making 0 always good and 1 always bad.
    - Remove wrong data or outliers.

    :parameter df: pandas dataframe containing all of the data
    :return: cleaned dataframe
    """

    df["Age"] = df["Age"] / 365
    df["Gender"] = df["Gender"] - 1

    # If the value of 'Cholesterol' or 'Glucose' is 1, make the value 0.
    # If the value is more than 1, make the value 1.
    for feat in ["Glucose", "Cholesterol"]:
        df[feat] = df[feat].apply(lambda x: 0 if x == 1 else 1)

    # Clean up data
    df = df[(df.BP_lo < df.BP_hi) &  # Diastolic pressure MUST be less than the systolic
            (df.BP_lo.between(50, 120)) &  # Diastolic blood pressure should be positive
            (df.BP_hi.between(100, 200)) &  # Reasonable values for systolic blood pressure
            (df.Gender < 2) &  # Gender can only be in [0, 1] = [Female, Male]
            # keep heights >= 0.25th percentile (h>=140cm)
            (df.Height >= df.Height.quantile(0.0025)) &
            # keep heights <= 99.75th percentile (h<=198cm)
            (df.Height <= df.Height.quantile(0.9999)) &
            # keep weights >= 0.25th percentile (w>=42kg=92.4lbs)
            (df.Weight >= df.Weight.quantile(0.0025)) &
            # keep weights <= 99.75th percentile (w<=133kg=292.6lbs)
            (df.Weight <= df.Weight.quantile(0.9975)) &
            # keep bmi >= 0.1th percentile (bmi>=16.1)
            (df.BMI >= df.BMI.quantile(0.001)) &
            (df.BMI <= df.BMI.quantile(0.999))]   # keep bmi <= 99.9th percentile (bmi<=59.2)

    return df

    - Change "Age" from days to years.
    - Make "Gender" values start from 0.
    - Normalize data by making 0 always good and 1 always bad.
    - Remove wrong data or outliers.

    :parameter df: pandas dataframe containing all of the data
    :return: cleaned dataframe
    
Change "Age" from days to years.
Make "Gender" values start from 0.
Normalize data by making 0 always good and 1 always bad.
Remove wrong data or outliers.
Change " Age " from days to years . Make " Gender " values start from 0 . Normalize data by making 0 always good and 1 always bad . Remove wrong data or outliers .
def cleanup(df: pd.DataFrame):
    df["Age"] = df["Age"] / 365
    df["Gender"] = df["Gender"] - 1
    for feat in ["Glucose", "Cholesterol"]:
        df[feat] = df[feat].apply(lambda x: 0 if x == 1 else 1)
    df = df[(df.BP_lo < df.BP_hi) &  
            (df.BP_lo.between(50, 120)) &  
            (df.BP_hi.between(100, 200)) &  
            (df.Gender < 2) &  
            (df.Height >= df.Height.quantile(0.0025)) &
            (df.Height <= df.Height.quantile(0.9999)) &
            (df.Weight >= df.Weight.quantile(0.0025)) &
            (df.Weight <= df.Weight.quantile(0.9975)) &
            (df.BMI >= df.BMI.quantile(0.001)) &
            (df.BMI <= df.BMI.quantile(0.999))]   
    return df
def cleanup ( df : pd . DataFrame ) : df [ "Age" ] = df [ "Age" ] / 365 df [ "Gender" ] = df [ "Gender" ] - 1 for feat in [ "Glucose" , "Cholesterol" ] : df [ feat ] = df [ feat ] . apply ( lambda x : 0 if x == 1 else 1 ) df = df [ ( df . BP_lo < df . BP_hi ) & ( df . BP_lo . between ( 50 , 120 ) ) & ( df . BP_hi . between ( 100 , 200 ) ) & ( df . Gender < 2 ) & ( df . Height >= df . Height . quantile ( 0.0025 ) ) & ( df . Height <= df . Height . quantile ( 0.9999 ) ) & ( df . Weight >= df . Weight . quantile ( 0.0025 ) ) & ( df . Weight <= df . Weight . quantile ( 0.9975 ) ) & ( df . BMI >= df . BMI . quantile ( 0.001 ) ) & ( df . BMI <= df . BMI . quantile ( 0.999 ) ) ] return df
Change "Age" from days to years.
Change " Age " from days to years .
"""
    - Change "Age" from days to years.
    - Make "Gender" values start from 0.
    - Normalize data by making 0 always good and 1 always bad.
    - Remove wrong data or outliers.

    :parameter df: pandas dataframe containing all of the data
    :return: cleaned dataframe
    """ # If the value of 'Cholesterol' or 'Glucose' is 1, make the value 0. # If the value is more than 1, make the value 1. # Clean up data # Diastolic pressure MUST be less than the systolic # Diastolic blood pressure should be positive # Reasonable values for systolic blood pressure # Gender can only be in [0, 1] = [Female, Male] # keep heights >= 0.25th percentile (h>=140cm) # keep heights <= 99.75th percentile (h<=198cm) # keep weights >= 0.25th percentile (w>=42kg=92.4lbs) # keep weights <= 99.75th percentile (w<=133kg=292.6lbs) # keep bmi >= 0.1th percentile (bmi>=16.1) # keep bmi <= 99.9th percentile (bmi<=59.2)
None
df
pd.DataFrame
pandas dataframe containing all of the data
pandas dataframe containing all of the data