인프런 커뮤니티 질문&답변
문제2번 질문있습니다!
해결된 질문
작성
·
25
0
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요
먼저 유사한 질문이 있었는지 검색해보세요
cond1 = df['구분'] = '발생건수'
cond2 = df['구분'] = '검거건수'
df1 = df[cond1]
df2 = df[cond2]
df2
이렇게 입력했는데
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.12/dist-packages/pandas/core/indexes/base.py in get_loc(self, key)
3804 try:
-> 3805 return self._engine.get_loc(casted_key)
3806 except KeyError as err:
index.pyx in pandas._libs.index.IndexEngine.get_loc()
index.pyx in pandas._libs.index.IndexEngine.get_loc()
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: '발생건수'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
2 frames
/usr/local/lib/python3.12/dist-packages/pandas/core/indexes/base.py in get_loc(self, key)
3810 ):
3811 raise InvalidIndexError(key)
-> 3812 raise KeyError(key) from err
3813 except TypeError:
3814 # If we have a listlike key, _check_indexing_error will raise
KeyError: '발생건수'
왜 발생건수에 대한 오류가 뜨는거죠? 정말 샅샅히 오류를 찾아봤는데 선생님이 하신거랑 똑같이한거같은데 ㅠㅠ
답변 1
0
퇴근후딴짓
지식공유자
에러는 똑같지 않아서 발생하는 겁니다.
거짓말 안해요 ㅎㅎㅎ
= 와 == 는 달라요
=는 대입
==는 왼쪽과 오른쪽이 같은지 비교합니다.
비교연산자를 써야하는데 대입을 했네요!
아래와 같이 수정하면 됩니다
cond1 = df['구분'] == '발생건수'
cond2 = df['구분'] == '검거건수'




