How to fix TypeError in spyder? How to fix TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''?

from sklearn.preprocessing import Imputer
imputer=Imputer(missing_values="np.nan",strategy="mean",axis=0)
imputer=imputer.fit(x[:,1:3])
x[:,1:3]=imputer.transform(x[:,1:3])



  Traceback (most recent call last):
  
  File "", line 3, in 
      imputer=imputer.fit(x[:,1:3])
  
  File
  "C:\Users\Nibir\Anaconda3\lib\site-packages\sklearn\preprocessing\imputation.py",
  line 167, in fit
      self.axis)
  
  File
  "C:\Users\Nibir\Anaconda3\lib\site-packages\sklearn\preprocessing\imputation.py",
  line 254, in _dense_fit
      mask = _get_mask(X, missing_values)
  
  File
  "C:\Users\Nibir\Anaconda3\lib\site-packages\sklearn\preprocessing\imputation.py",
  line 30, in _get_mask
      if value_to_mask == "NaN" or np.isnan(value_to_mask):
  
  TypeError: ufunc 'isnan' not supported for the input types, and the
  inputs could not be safely coerced to any supported types according to
  the casting rule ''safe''
You might try it without the double quotes around the np.NaN and do not forget to import numpy (import numpy as np)

As a sidenote, you should use SimpleImputer instead of Imputer:

Imputer was deprecated in version 0.20 and will be removed in 0.22. Import impute.SimpleImputer from sklearn instead.