【发布时间】:2018-09-26 22:32:09
【问题描述】:
我尝试使用 imputer 将数据库的所有 NaN 部分替换为其相关列的平均值。例如,我想修复我的数据库中工资列下的空白条目,并且我希望该空白部分填充该列下的平均工资值。我尝试按照教程执行此操作,但我认为视频已过时,导致此错误。
代码:
#Data Proccesing
#Importing the Libaries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv("Data.csv")
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
#Taking care of Missig Data
from sklearn.preprocessing import Imputer
#The source of all the problems
imputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0)
imputer = imputer.fit(X[:, 1:3])
X[:, 1:3] = imputer.transform
【问题讨论】:
-
该错误准确地解释了如何解决该问题。
float() argument must be a string or a number, not 'method'。为了帮助诊断,您可以拆分代码并使用type函数来验证类型。 -
请不要在图片中发布终端/代码输出。原因请看这里:unix.meta.stackexchange.com/q/4086/40481
-
谢谢你,从现在开始我将不再这样做。
标签: python machine-learning data-science