【问题标题】:Why is SimpleImputer's fit_transform not working for dataframe in google colab?为什么 SimpleImputer 的 fit_transform 不适用于 google colab 中的数据框?
【发布时间】:2020-04-27 00:23:08
【问题描述】:
imp = SimpleImputer(missing_values=np.nan, strategy='most_frequent')
weather_test = imp.fit_transform(weather_test)

当 weather_test 是 pandas 数据框时,上面的代码在 google colab 中引发错误。 但是当我将 weather_test 更改为 numpy 数组时,它可以工作。

imp = SimpleImputer(missing_values=np.nan, strategy='most_frequent', verbose=0)
weather_test = imp.fit_transform(np.array(weather_test))

【问题讨论】:

  • 您介意添加完整的错误吗?

标签: pandas scikit-learn google-colaboratory


【解决方案1】:

Scikit-learn 的 API 方法通常假设输入是一个 numpy 数组而不是 pandas 数据帧。有关如何将此功能与数据框一起使用的示例,请参阅How to use sklearn fit_transform with pandas and return dataframe instead of numpy array?

【讨论】:

    猜你喜欢
    • 2019-09-25
    • 2021-04-17
    • 2020-12-22
    • 2021-09-07
    • 2022-12-15
    • 2021-11-25
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多