Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 602 Bytes

pd_12_impute_cols.md

File metadata and controls

27 lines (18 loc) · 602 Bytes
for c in column_names[1:]:
    df[c] = df[c].replace("n", 0)
    df[c] = df[c].replace("y", 1)
    df[c] = df[c].replace("?", np.nan)
    df[c] = df[c].astype(float)
    df[c] = df[c].replace(np.nan, df[c].mean())

representatives = representatives.replace('y',1)
representatives = representatives.replace('n',0)
representatives = representatives.replace('?',np.nan)

#replace ? values with the column mean
for column in range(1,17):
    colmean = representatives[column].mean()
    representatives.loc[np.isnan(representatives[column]), column] = colmean

representatives.head()