为什么第一个代码不起作用,而第二个代码起作用?
Why isn't the first code not working, whereas second does?
第一个代码片段:
imp.fit_transform(dataset['Age'].values.reshape(-1,1))
dataset['Age'] = dataset['Age'].values.reshape(-1,1)
第二个代码片段:
imp.fit(dataset['Age'].values.reshape(-1, 1))
dataset['Age'] = imp.transform(dataset['Age'].values.reshape(-1, 1))
第一个代码片段没有对我的数据集的年龄列进行任何更改。
第一个代码不会更改 Age
列,因为您没有要求它这样做;) 您应用了 fit_transform
函数,但没有使用它来更改数据集。
我不知道什么是 imp
,但是第一段代码的更正确的实现肯定是这样的:
dataset['Age'] = imp.fit_transform(dataset['Age'].values.reshape(-1,1))
第一个代码片段:
imp.fit_transform(dataset['Age'].values.reshape(-1,1))
dataset['Age'] = dataset['Age'].values.reshape(-1,1)
第二个代码片段:
imp.fit(dataset['Age'].values.reshape(-1, 1))
dataset['Age'] = imp.transform(dataset['Age'].values.reshape(-1, 1))
第一个代码片段没有对我的数据集的年龄列进行任何更改。
第一个代码不会更改 Age
列,因为您没有要求它这样做;) 您应用了 fit_transform
函数,但没有使用它来更改数据集。
我不知道什么是 imp
,但是第一段代码的更正确的实现肯定是这样的:
dataset['Age'] = imp.fit_transform(dataset['Age'].values.reshape(-1,1))