application_vnd.jupyter.stderr_output_1.png
import pandas as pd

def get_nan_dummy(series):
    """Given a Series containing NaN and several classes return a dummy Series
    indicating 0 for NaN and 1 for non-NaN data
    Parameters
    ----------
    - series : pd.Series, input series or col to dummify
    Return
    ------
    - s : pd.Series the dummy Series
    """
    s = series.notna().astype(int).astype('category')
    s.name = f'{series.name}_abs_pres'
    return s

data = pd.read_csv('./train.csv')
data = data.drop('Id', axis=1)
new_cols = data.columns.to_list()
new_cols.reverse()
data = data[new_cols]
all_nan = data.isnull().sum().sort_values(ascending=False)
all_nan = all_nan[all_nan > 0]
cols = ['PoolQC', 'Alley', 'Fence', 'FireplaceQu', 'LotFrontage', 'MasVnrArea', 'GarageQual', 'BsmtQual']
abs_pres_series = []
for col in cols:
    abs_pres_series.append(get_nan_dummy(data[col]))
abs_pres_series = pd.concat(abs_pres_series, axis=1)
data = pd.concat([data, abs_pres_series], axis=1)
a = data['BsmtExposure'].isna()[data['BsmtExposure'].isna() == True].index
b = data['BsmtCond'].isna()[data['BsmtCond'].isna() == True].index
mystery_row = [x for x in set(a) - set(b)]
mystery_row = mystery_row[0]
data.loc[mystery_row, ['BsmtExposure', 'BsmtFinType2', 'BsmtCond', 'BsmtQual']]
data.drop(mystery_row, axis=0, inplace=True)