python-3.x - 我正在使用 LabelEncoder 在我的数据框中标记分类数据。我收到此错误。'(slice(None, None, None), 2)' 是无效键
问题描述
我有一个分类数据,我正在尝试使用 LabelEncoder 对数据进行编码以运行回归模型。但是,我收到此错误。
'(slice(None, None, None), 2)' 是无效键
我正在尝试对数据框中的第三列进行编码。
from sklearn.preprocessing import LabelEncoder
labelencoder = LabelEncoder()
df[:, 2] = labelencoder.fit_transform(df[:, 2])
假设第 3 列的数据如下:
Col3
A
B
D
D
A
B
B
预期结果是:
Col3
1
2
3
3
1
2
2
解决方案
推荐阅读
- javascript - 使用 Firestore 获取文档集合
- excel - 在标签标题上查找行
- node.js - 在 Node.js 中压缩包含换行符的文本文件会导致 gzip 文件损坏
- python - 如何使用 pandas 和 pytest 进行 TDD?
- symfony - 实体期望对象返回 symfony
- javascript - Reactjs:将侧边栏组件导入到不同的页面
- python - 无法单击带有硒的按钮
- databricks - 无法通过 DeltaTable.forPath 查看新创建的增量表
- c# - 如何在 while 循环中进行睡眠?
- odoo - 在尝试将应用程序/模块迁移到 odoo 13 时,我得到 KeyError: 'tax_line_ids'