Posting as it might help future users.
As correctly pointed out by others, np.isnan won’t work for object
or string
dtypes. If you’re using pandas, as mentioned here you can directly use pd.isnull
, which should work in your case.
import pandas as pd
import numpy as np
var1 = ''
var2 = np.nan
>>> type(var1)
<class 'str'>
>>> type(var2)
<class 'float'>
>>> pd.isnull(var1)
False
>>> pd.isnull(var2)
True