Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入类型Python插补器不支持Isnan_Python_Pandas_Scikit Learn - Fatal编程技术网

输入类型Python插补器不支持Isnan

输入类型Python插补器不支持Isnan,python,pandas,scikit-learn,Python,Pandas,Scikit Learn,我一直在关注这一系列教程,并且完全按照导师对我所做的那样做,当然,代码中提到了这个错误。一个可能的解决方案当然会很有帮助。提前谢谢 尝试: 或 如错误中所述:如果value_to_mask==“NaN”或np.isnan(value_to_mask):TypeError:ufunc'isnan'不支持输入类型,并且无法根据强制转换规则“safe”将输入安全强制为任何支持的类型,哪一行会导致这种情况error@Primusa插补器=插补器(缺失值…)一个。可能无法处理字符串值。首先将其转换为X[:

我一直在关注这一系列教程,并且完全按照导师对我所做的那样做,当然,代码中提到了这个错误。一个可能的解决方案当然会很有帮助。提前谢谢

尝试:


错误中所述:如果value_to_mask==“NaN”或np.isnan(value_to_mask):TypeError:ufunc'isnan'不支持输入类型,并且无法根据强制转换规则“safe”将输入安全强制为任何支持的类型,哪一行会导致这种情况error@Primusa插补器=插补器(缺失值…)一个。可能无法处理字符串值。首先将其转换为X[:,1:3].aType(str),然后再试一次again@cᴏʟᴅsᴘᴇᴇᴅ 我一直在使用整数而不是字符串。同样的错误。第一个有效,第二个无效,你知道为什么吗?@DawoodZaidi要了解更多细节,你可以用这个作为支持答案
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

#Import Data set

dataset= pd.read_csv('Data.csv') 
X = dataset.iloc[:,:-1].values
Y = dataset.iloc[:,3].values

#Taking Care of The Missing Data
from sklearn.preprocessing import Imputer

imputer = Imputer(missing_values='nan',strategy='mean',axis=0)
imputer = imputer.fit(X[:,1:3])

X[:,1:3] = imputer.transform(X[:,1:3])
Error : 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''
imputer = Imputer(missing_values=np.nan,strategy='mean',axis=0)
imputer = Imputer(missing_values='NaN',strategy="mean",axis=0)