擅长:python、mysql、java
<p>我猜由于字符串“Nan”,您的LotFrontage列数据存储为对象数据类型。请使用此类型查找。它很可能会给出object/string。</p>
<pre><code>print(reduced_data.LotFrontage.values.dtype)
</code></pre>
<p>输入器只在浮子上工作。</p>
<p><strong>第一次进近:</strong></p>
<p>您可以执行以下操作:
1) 将列类型转换为浮点
2) 柱面平均数
3) 使用pandas dataframe函数fillna在dataframe中填充nan。</p>
<pre><code>reduced_data.LotFrontage = pd.to_numeric(reduced_data.LotFrontage, errors='coerce')
m = reduced_data.LotFrontage.mean(skipna=True)
reduced_data.fillna(m)
</code></pre>
<p>以上代码将在数据帧中填充任何存在nan的地方。</p>
<p><strong>第二种方法:</strong></p>
<pre><code>reduced_data.LotFrontage = pd.to_numeric(reduced_data.LotFrontage, errors='coerce')
imputer = Imputer()
features = reduced_data.iloc[:,:-1].values
imputer.fit(features[:,2])
</code></pre>