我正在尝试使用Python 2.7将数据框转换为数组,但出现错误。
这是我的代码:
train = arff.loadarff(open('/Users/cristinamulas/train.arff', 'r'))
train = pd.DataFrame([train])
train = train[['sepal_length','sepal_width','petal_length','petal_width','CLASS_LABEL']].values
错误
File "/anaconda2/lib/python2.7/site-packages/pandas/core/frame.py", line 2726, in _getitem_array
indexer = self.loc._convert_to_indexer(key, axis=1)
File "/anaconda2/lib/python2.7/site-packages/pandas/core/indexing.py", line 1327, in _convert_to_indexer.format(mask=objarr[mask]))
KeyError: "['sepal_length' 'sepal_width' 'petal_length' 'petal_width' 'CLASS_LABEL'] not in index"
答案 0 :(得分:0)
直接尝试以下代码
train.values
从代码行中删除列名。