尝试导入我的数据集(从0开始计数的18列),我收到此错误:
文件“ C:/Users/ASUS/PycharmProjects/PA/BestAcc.py”,第23行,在 Y = churn.iloc [:, 18] .values文件“ C:\ Python35 \ lib \ site-packages \ pandas \ core \ indexing.py”,行1472,在 getitem 返回self._getitem_tuple(key)文件“ C:\ Python35 \ lib \ site-packages \ pandas \ core \ indexing.py”,行2013,在 _getitem_tuple self._has_valid_tuple(tup)文件“ C:\ Python35 \ lib \ site-packages \ pandas \ core \ indexing.py”,第222行,在 _has_valid_tuple self._validate_key(k,i)文件“ C:\ Python35 \ lib \ site-packages \ pandas \ core \ indexing.py”,行1957,在 _validate_key self._validate_integer(key,axis)文件“ C:\ Python35 \ lib \ site-packages \ pandas \ core \ indexing.py”,行2009,在 _validate_integer 提高IndexError(“单个位置索引器超出范围”)IndexError:单个位置索引器超出范围
代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
churn = pd.read_csv("HR.csv")
#import colums except the first one in the dataset
X = churn.iloc[:, 1:18].values
Y = churn.iloc[:, 18].values
答案 0 :(得分:0)
iloc
在pandas
的更高版本中已被弃用-我建议改用loc
-
X = churn.loc[:, churn.columns[1:18]]
Y = churn.loc[:, churn.columns[18]]