text_html_output_1.png text_plain_output_1.png
def fill_missing(df):
    """
    Fill nan values or missing data with mean or most commond value...
    """
    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
    numeric_tmp = df.select_dtypes(include=numerics)
    categ_tmp = df.select_dtypes(exclude=numerics)
    for col in numeric_tmp.columns:
        print(col)
        df[col] = df[col].fillna(value=df[col].mean())
    for col in categ_tmp.columns:
        print(col)
        df[col] = df[col].fillna(value=df[col].mode()[0])
    print('...')
    return df