TypeError:'int'类型的对象没有len()?

时间:2018-05-06 08:48:27

标签: python

# Logistic Regression

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Loan.csv')
X = dataset.iloc[:, 16: 17 ].values
y = dataset.iloc[:, 20].values


# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder = LabelEncoder()
X[:, 0] = labelencoder.fit_transform(X[:, 0])
onehotencoder = OneHotEncoder(categorical_features = 1)
X = onehotencoder.fit_transform(X).toarray()

当我编写代码时,我得到的错误就像'int'类型的对象没有len()?

1 个答案:

答案 0 :(得分:0)

在进行更正后已修复:

onehotencoder = OneHotEncoder(categorical_features = [1]*)

我认为这是因为python要我们指定哪一列,以解释对“ []”的需要。