def type_convert_mean(dataframe, colname, data_type):
    """Replace mistyped values with the mean on dataframe[colname]"""
    col = dataframe[colname]
    col_numerics = col.loc[col.apply(lambda x: isinstance(x, (int, float)))]
    dataframe.loc[col.notnull() & col.apply(lambda x: not isinstance(x,
        data_type)), colname] = col_numerics.mean()
    return dataframe
