vendredi 22 novembre 2019

Python - checking if value in dataframe in nan in an if statement

I am trying to create a column that tells whether each row in another column is NaN or not.

if top20X['cc_gb_15'].isna() == True:
    top20X['cc_gb_15_null'] = 1
else:
    0

However, the code trips up on the first line and I receive the following error:

"The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."

Funnily enough top20X['cc_gb_15'].isna() works just fine in telling me whether that row is NaN or not, but when i try to found out if its NaN it won't do it.

Aucun commentaire:

Enregistrer un commentaire