람다 관련 질문이요 ㅠ
데이터마님에 전처리100문제 훑어보고 있어요
람다식이 있어서 시험환경 문제1의 데이터로 응용해서 해보려니 안되네요 ㅠㅠ
그냥 딕셔너리 형태를 넣으면 되구요...
help에서는 딕셔너리 아니면 시리즈를 넣으라고 되어있는데 그래서 안되는건지...
a.cyl = a.cyl.astype('object')
dic = {
'4' : 'N',
'6' : 'a',
'8' : 'b'
}
a['newcyl'] =a.cyl.map(dic)
print(a.cyl)
a['newcyl'] =a.cyl.map(lambda x: dic[x])
> Makefile:6: recipe for target 'py3_run' failed
make: *** [py3_run] Error 1
Traceback (most recent call last):
File "/goorm/Main.out", line 18, in <module>
a['newcyl'] =a.cyl.map(lambda x: dic[x])
File "/usr/local/lib/python3.9/dist-packages/pandas/core/series.py", line 4237, in map
new_values = self._map_values(arg, na_action=na_action)
File "/usr/local/lib/python3.9/dist-packages/pandas/core/base.py", line 880, in mapvalues
new_values = map_f(values, mapper)
File "pandas/_libs/lib.pyx", line 2870, in pandas._libs.lib.map_infer
File "/goorm/Main.out", line 18, in <lambda>
a['newcyl'] =a.cyl.map(lambda x: dic[x])
KeyError: 6
help
map(arg, na_action=None) -> 'Series' method of pandas.core.series.Series instance
Map values of Series according to an input mapping or function.
Used for substituting each value in a Series with another value,
that may be derived from a function, a ``dict`` or
a :class:`Series`.
Parameters
----------
arg : function, collections.abc.Mapping subclass or Series
Mapping correspondence.
na_action : {None, 'ignore'}, default None
If 'ignore', propagate NaN values, without passing them to the
mapping correspondence.
답변 1
불균형 데이터인데 stratify 없을 때 점수가 높은 경우
0
2
0
수강연장 관련 문의
0
12
2
안녕하세요 강사님 문의사항이 있습니다
0
20
1
수강 연장 문의
0
31
4
수강기간 연장 관련 문의
0
28
2
작업형2모의문제3_updated2026.10
0
47
2
안녕하세요. 수강연장 신청드립니다
0
26
2
코랩 링크
0
27
2
작업형2 모의문제2 updated 2026.10 질문
0
41
2
카이제곱 독립성검정 질문합니다.
0
38
2
기출 7회 작업형2 평가지표 문의드립니다.
0
30
2
수강연장 문의 드립니다!
0
54
3
수강연장 문의드립니다
0
43
4
작업형2모의문제3_updated2026.10
0
52
2
작업형2 모의문제3_updated2026.10
0
47
2
38강에서 불균형 데이터 처리하는 stratify를 꼭 해줘야하는건지 질문합니다.
0
48
2
수강강의 연장 관련 문의
0
61
2
작업형1_연습문제1 section2
0
47
2
수강기간 연장 문의드립니다
0
50
2
작업형2 모의문제2_updated2026.10
0
61
2
수강기간 연장문의
0
46
2
작업형 2 질문
0
55
2
강의 연장 관련하여 문의드립니다.
0
53
2
섹션7 자료 다운로드
0
52
2





