람다 관련 질문이요 ㅠ
데이터마님에 전처리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
수강 연장 문의드립니다.
0
24
2
강의 연장 문의
0
30
2
수강 신청 연장 문의드립니다.
0
44
2
작업형 1번문제... 환경관련
0
30
2
12회 기출은 언제 업데이트 될까요??
0
39
2
8/6 작성한 연장문의 질문글에 대한 재요청
0
38
2
수강기간 연장 문의
0
40
2
수강기간 연장문의
0
37
2
수강기간 연장 요청 문의드립니다
0
38
2
수강 기간 연장 문의
0
47
2
수강연장 가능 문의 (기간 약 한달반)
0
60
2
수강기간 연장 가능할까요 선생님
0
74
2
Section15. 수업에 사용하는 데이터 주소가 다 보이지 않아서 실습을 위한 데이터를 다운 받지 못하고 있습니다.
0
56
3
수강연장요청 문의
0
91
2
아무래도 다음 시험 연장은 어렵겠죠?
0
109
2
빅분기 12회 결과 관련 문의
0
113
1
책이랑 강의랑 순서나 예제가 다른것 같네요
0
82
2
수강연장 문의
0
107
2
재검토 요청 방법 좀 알려주셔요...-.-;;
0
106
2
12회 실기 질문(작업형 2)
0
92
2
뒤로가기 버튼 같은 것이 있나요?
0
66
1
강의 연장 문의
0
99
2
출력값 질문
0
74
2
수업노트가 어디에 있나요?
0
63
1





