작업형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'컬럼을 제거한 것이 아닌가 싶어요
코드를 다시 확인해주세요
강의 관련 질문
0
11
0
작업형 2 질문
0
16
2
강의 연장 관련하여 문의드립니다.
0
18
1
섹션7 자료 다운로드
0
20
2
작업형 1 연습문제 Section12
0
18
2
수강기간 연장 문의
0
30
1
안녕하세요, 혹시 수강기간 연장이 가능할까요?
0
28
2
판다스 강의자료는 어디서 받을 수 있나요?
0
27
2
작업형2 모의고사3 자료 업데이트 요청
0
34
4
수강 연장가능여부 문의드립니다!
0
38
2
수강기간 연장 문의드립니다!
0
36
2
최빈값
0
36
2
수강 가이드라인
0
31
2
수강 연장 가능 여부 문의
0
56
2
강의 구매했는데 교재 필수일까요
0
44
2
수강기간 연장 가부 문의드립니다.
0
41
2
수강기간 연장이 가능한지 양해를 구하며 문의를 드립니다.
0
43
2
작업형2 모의문제2에서 drop이랑 인코딩
0
52
3
인코딩을 다 꼭 해봐야하는지
0
51
2
안녕하세요? 강사님 질문있습니다.(인코딩관련)
0
62
2
이진분류에서 양성 클래스가 0일 때 평가 방법
0
46
2
원핫인코딩 전 train과 test 병합여부
0
53
2
수강기간 연장
0
72
2
29강 작업2형의 이상치 처리
0
70
2





