dimanche 12 août 2018

Function that first checks for NaN, then replaces values based on another column

I am trying to define a function that replaces the value in 'BsmtFinType1' based on the value of the column 'MSSubClass'. However, I want it to first check to make sure the 'value to be replaced' is NaN. If it has a value, it does not replace it. I am not entirely sure why my sample won't work. After running it, none of the values update. If I remove the first 'If' Statement, it runs and replaces values just fine. Any ideas?

# Fill Basement Finishes
def bsmt_fin(x):
    if x['BsmtFinType1'] != np.NaN:
        return x['BsmtFinType1']
    elif x['MSSubClass'] < 60:
        return 'Unf'
    else:
        return 'LwQ'

all_data['BsmtFinType1'] = all_data.apply(lambda x: bsmt_fin(x), axis=1)

Aucun commentaire:

Enregistrer un commentaire