커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
코드에서 오류가 납니다
undefined주차
북마크
김*영
댓글
3
추천
0
조회수
23
조회수
23
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


강의에서는 5654라고 결과가 잘 나오는데 오류가 납니다.

그대로 복사했는데 오류가 나서 질문드립니다.


스파르타 즉문즉답




import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rc('font', family='NanumBarunGothic') #한글 깨짐 방지 글꼴 설정


sparta_data = pd.read_table('/content/user_db1.csv', sep = ".")


#sparta_data['group'] ==1 이라는 조건을 두고 그것이 일치하는 user의 수를 세면 됩니다!
#이때의 ==은 우리가 알고 있는 "equal" = 과 동일한 뜻입니다! (파이선에서 = 는 변수 지정 할때만 쓰입니다. 소곤소곤)
#할인 혜택 받지 않은 사람의 결제 수 
sum_of_students_by_discounted = sparta_data[sparta_data['group']==1]['user_id'].count()
sum_of_students_by_discounted


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key)
   3790         try:
-> 3791             return self._engine.get_loc(casted_key)
   3792         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: 'group'
The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)

2 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key)
   3796             ):
   3797                 raise InvalidIndexError(key)
-> 3798             raise KeyError(key) from err
   3799         except TypeError:
   3800             # If we have a listlike key, _check_indexing_error will raise

KeyError: 'group'
취소
 공유
취소
댓글 0
댓글 알림
나의얼굴