I am trying to use train_test_split
to split my data. However, I am getting an index error. I pasted part of the error message below. I am using Python 3.5 version and sklearn
0.18.1. The code worked with my previous dataset that was different. Features here are in Pandas DataFrame
and labels are in Pandas
Series
.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=0.4, random_state=1)
KeyError
Traceback (most recent call last)
/apps/anaconda/anaconda-3.5/lib/python3.5/site-
packages/pandas/indexes/base.py in get_loc(self, key, method, tolerance)
2133 try:
-> 2134 return self._engine.get_loc(key)
2135 except KeyError:<br><br>
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4443)()<br><br>
pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:4289)()<br><br>
pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13733)()<br><br>
pandas/src/hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13687)()<br><br>
KeyError: 0