2017-12-11 16 views
-1

, 내가 무엇을 아무 생각이 :테스트 트레이닝 스플릿을 실행할 때 키 오류가 발생합니다. 어떻게해야합니까? 다음 코드를 실행할 때 나는 문제가 있어요

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

종종 이것은 데이터 프레임에 'Close' 열이 포함되어 있지 않다는 것을 의미합니다. 후행 공백 또는 잘못된 대/소문자가 원본이 될 수 있습니다. 실제 열 이름

' Close' 또는 'close' 을 좋아하지되어 있는지 확인합니다.

+0

가장 쉬운 방법은 다음과 같습니다 :'print (fd2.columns.tolist())' – MaxU