작업형2 모의문제 1
코랩으로 입력중인데
from sklearn.preprocessing import LabelEncoder cols = ['Gender','Education_Level','Marital_Status','Income_Category','Card_Category'] for col in cols: le=LabelEncoder() train[col] = le.fit_transform(train[col]) test[col] = le.transform(test[col]) target = train.pop('Attrition_Flag')
에러가 나와요 왜그런거죠
KeyError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3801 try:
-> 3802 return self._engine.get_loc(casted_key)
3803 except KeyError as err:
6 frames
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Attrition_Flag'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3802 return self._engine.get_loc(casted_key)
3803 except KeyError as err:
-> 3804 raise KeyError(key) from err
3805 except TypeError:
3806 # If we have a listlike key, checkindexing_error will raise
KeyError: 'Attrition_Flag'
답변 1
0
KeyError: 'Attrition_Flag'는 'Attrition_Flag'컬럼이 없을 때 발생합니다.
아마 이전코드에서 train에서 이미 'Attrition_Flag'컬럼을 제거한 것이 아닌가 싶어요
코드를 다시 확인해주세요
작업형2 모의문제1 (30강)
0
18
1
수강 기간 연장 문의 드립니다.
0
21
1
수강 계획과 관련해 문의 드립니다.
0
19
1
작업형1 - 연습문제 16~39 풀이는 몇강을 보면 되나요?
0
45
2
작업형 1 -연습문제 4-6
0
32
2
작업형 1 유형 부분
0
40
2
작업형 1 (삭제예정, 구 버전)
0
50
2
수강기간 연장 문의드립니다.
0
35
1
2유형 레이블 인코딩 VS 원핫 인코딩
0
36
3
수강기간 연장 문의드립니다.
0
38
1
인덱스 슬라이싱
0
35
2
질문 드립니다.
0
50
2
강의 내용 관련 질문드립니다~
0
46
2
수강 연장 문의
0
63
2
강의자료 일괄 다운로드
0
58
2
수강기간 연장 문의드립니다
0
47
2
list 문제 질문드립니다~
0
38
2
빅분기 실기 12회 재도전
0
62
2
강의 기간 연장 가능여부 검토 요청건
0
49
2
수강기간 연장 문의 드립니다
0
45
2
수강기간 연장 문의드립니다
0
52
2
질문이요
0
57
2
수강기간 연장 문의드립니다.
0
60
2
문제 3-2 질문드립니다
0
47
2





