작업형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'컬럼을 제거한 것이 아닌가 싶어요
코드를 다시 확인해주세요
1유형 강의 다 나간 후 어떻게 할까요?
0
16
1
점수차가 많이 나는데 따로 하신게 있으신가요?
0
13
1
작업형1 모의문제 4번에 3)문제 질문
0
22
2
이상치 전처리 작업
0
25
2
평가결과값 문의
0
29
2
시계열 데이터 날짜와 시간 format
0
36
2
평가지표 F1 스코어 질문드립니다.
0
27
2
작업형 2 기출7회분에서
0
38
2
작업형2 모의문제1 (30강)
0
34
2
수강 기간 연장 문의 드립니다.
0
42
2
수강 계획과 관련해 문의 드립니다.
0
30
2
작업형1 - 연습문제 16~39 풀이는 몇강을 보면 되나요?
0
50
2
작업형 1 -연습문제 4-6
0
38
2
작업형 1 유형 부분
0
42
2
작업형 1 (삭제예정, 구 버전)
0
51
2
수강기간 연장 문의드립니다.
0
38
2
2유형 레이블 인코딩 VS 원핫 인코딩
0
37
3
수강기간 연장 문의드립니다.
0
45
2
인덱스 슬라이싱
0
37
2
질문 드립니다.
0
50
2
강의 내용 관련 질문드립니다~
0
46
2
수강 연장 문의
0
63
2
강의자료 일괄 다운로드
0
62
2
수강기간 연장 문의드립니다
0
48
2





