运行以下代码时出现问题,我不知道该怎么做:
fd2['Close'] = fd2['Close'].apply(lambda x: 1 if x == '300' else 0)
X_train, X_test, y_train, y_test = \
train_test_split(fd2['Volume_(BTC)'].values, fd2['Close'].values)
KeyError
Traceback (most recent call last)
/Users/traviskerr/anaconda3/lib/python3.6/site-
packages/pandas/core/indexes/base.py in get_loc(self, key, method,
tolerance)
2392 try:
-> 2393 return self._engine.get_loc(key)
2394 except KeyError:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc
(pandas/_libs/index.c:5239)()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc
(pandas/_libs/index.c:5085)()
pandas/_libs/hashtable_class_helper.pxi in
pandas._libs.hashtable.PyObjectHashTable.get_item
(pandas/_libs/hashtable.c:20405)()
pandas/_libs/hashtable_class_helper.pxi in
pandas._libs.hashtable.PyObjectHashTable.get_item
(pandas/_libs/hashtable.c:20359)()
KeyError: 'Close'
During handling of the above exception, another exception occurred:
KeyError
请帮忙! 谢谢!
答案 0 :(得分:0)
这通常意味着您的数据框不包含'Close'
列。
尾随空格或错误的大写/小写字符可以作为源。确保您的实际列名不像
' Close'
要么
'close'