【问题标题】:Isnan is not supported for the input types Python Imputer输入类型 Python Imputer 不支持 Isnan
【发布时间】:2018-09-24 05:29:06
【问题描述】:
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''

【问题讨论】:

  • 错误:如果 value_to_mask == "NaN" 或 np.isnan(value_to_mask): TypeError: 输入类型不支持 ufunc 'isnan',并且输入无法安全地强制转换为任何支持的类型根据强制转换规则“安全”
  • 哪一行导致该错误
  • @Primusa the Imputer = Imputer(Missing Values...) one.
  • 可能不适用于字符串值。先转换X[:,1:3].astype(str)再试试
  • @cᴏʟᴅsᴘᴇᴇᴅ 我一直在使用整数而不是字符串。同样的错误。

标签: python pandas scikit-learn


【解决方案1】:

试试:

imputer = Imputer(missing_values=np.nan,strategy='mean',axis=0)

imputer = Imputer(missing_values='NaN',strategy="mean",axis=0)

documentation中所述

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-12-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-17
  • 2020-02-18
  • 2019-03-10
  • 2017-04-10
相关资源
最近更新 更多