커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
2주차 2-6강 함수로 만들어보기 실습 오류
undefined주차
북마크
권*민
댓글
1
추천
0
조회수
5
조회수
5
답변 완료

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

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


def make_rate(code) 함수를 만들고, 바로 그 아래에 강의와 동일하게 코드를 작성하여 실행을 했는데, Close 키가 존재하지 않다는 오류가 발생합니다



스파르타 즉문즉답





작성한 코드 및 에러 메세지

---------------------------------------------------------------------------
DateParseError                            Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/datetimes.py in get_loc(self, key)
    603             try:
--> 604                 parsed, reso = self._parse_with_reso(key)
    605             except (ValueError, pytz.NonExistentTimeError) as err:


6 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/datetimes.py in _parse_with_reso(self, label)
    559     def _parse_with_reso(self, label: str):
--> 560         parsed, reso = super()._parse_with_reso(label)
    561 

/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/datetimelike.py in _parse_with_reso(self, label)
    269 
--> 270         parsed, reso_str = parsing.parse_datetime_string_with_reso(label, freqstr)
    271         reso = Resolution.from_attrname(reso_str)

parsing.pyx in pandas._libs.tslibs.parsing.parse_datetime_string_with_reso()

parsing.pyx in pandas._libs.tslibs.parsing.dateutil_parse()

DateParseError: Unknown datetime string format, unable to parse: Close
The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
<ipython-input-53-d2945cee2d28> in <cell line: 3>()
      1 df = pd.DataFrame()
      2 
----> 3 df['AAPL'] = make_rate('AAPL')
      4 
      5 df.plot()

<ipython-input-51-4b17a07c79a2> in make_rate(code)
      3   original = df['Close'].iloc[0]
      4   df = df['Close']/ original -1
----> 5   return df['Close']

/usr/local/lib/python3.10/dist-packages/pandas/core/series.py in __getitem__(self, key)
   1038 
   1039         elif key_is_scalar:
-> 1040             return self._get_value(key)
   1041 
   1042         # Convert generator to list before going through hashable part

/usr/local/lib/python3.10/dist-packages/pandas/core/series.py in _get_value(self, label, takeable)
   1154 
   1155         # Similar to Index.get_value, but we do not fall back to positional
-> 1156         loc = self.index.get_loc(label)
   1157 
   1158         if is_integer(loc):

/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/datetimes.py in get_loc(self, key)
    604                 parsed, reso = self._parse_with_reso(key)
    605             except (ValueError, pytz.NonExistentTimeError) as err:
--> 606                 raise KeyError(key) from err
    607             self._disallow_mismatched_indexing(parsed)
    608 

KeyError: 'Close'


Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.

Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴