【发布时间】:2017-09-03 13:13:58
【问题描述】:
我来了
TypeError: unhashable type: 'slice'
在执行以下代码以在 Python 中编码分类数据时。有人可以帮忙吗?
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
dataset = pd.read_csv('50_Startups.csv')
y=dataset.iloc[:, 4]
X=dataset.iloc[:, 0:4]
# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 3] = labelencoder_X.fit_transform(X[:, 3])
【问题讨论】:
-
csv 文件中有什么?你在哪一行得到了 TypeError?
-
请将相应的堆栈跟踪添加到您的问题中。
-
告诉使用
dataset?我怀疑它的“iloc”需要一个字符串列标签,而不是像切片这样的二维数组。该错误意味着slice(例如 0:4)被用作字典键或类似的东西。
标签: python pandas numpy matplotlib