TypeError: ufunc ‘isnan’ not supported for the input types, and the inputs could not be safely coerced

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)