inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

173만명의 커뮤니티!! 함께 토론해봐요.

데이터 전체에 대한 수익률을 계산하고 싶은데 오류가 뜹니다

미해결

파이썬 증권 데이터 수집과 분석으로 신호와 소음 찾기

배운걸 활용해 Financial Data Reader KRX종목 전부에 대한 수익률을 계산하려고 합니다. #다음 수식으로 FDR df의 "Name"과 "Symbol"만 남겼고 df_dic = df[["Name", "Symbol"]] df_dictionary = df_dic.values df_dictionary #dict 함수를 활용해 numpy array를 dictionary 형태로 변환했습니다. df_list = dict(df_dictionary) df_list #수업에서 배운대로 다음 수식을 적어 상장종목 전부에 대한 종가를 얻으려고 했는데 item_list = [] for item_code in df_list.values(): close = fdr.DataReader(item_code, "2020", "2023")['Close'] item_list.append(close) #다음과 같은 에러메시지가 뜹니다 eyError Traceback (most recent call last) ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc (self, key, method, tolerance) 3360 try : -> 3361 return self . _engine . get_loc ( casted_key ) 3362 except KeyError as err : ~\anaconda3\lib\site-packages\pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc () ~\anaconda3\lib\site-packages\pandas\_libs\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 : 'Close' The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_96644/3549058376.py in <module> 1 item_list = [ ] 2 for item_code in df_list . values ( ) : ----> 3 close = fdr . DataReader ( item_code , "2020" , "2023" ) [ 'Close' ] 4 item_list . append ( close ) ~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__ (self, key) 3456 if self . columns . nlevels > 1 : 3457 return self . _getitem_multilevel ( key ) -> 3458 indexer = self . columns . get_loc ( key ) 3459 if is_integer ( indexer ) : 3460 indexer = [ indexer ] ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc (self, key, method, tolerance) 3361 return self . _engine . get_loc ( casted_key ) 3362 except KeyError as err : -> 3363 raise KeyError ( key ) from err 3364 3365 if is_scalar ( key ) and isna ( key ) and not self . hasnans : KeyError : 'Close' 이거 혹시 2020~2022 사이 종가데이터가 없는 종목이 있어서 그런건가요?

  • 파이썬
  • numpy
  • dict
  • 웹-크롤링
  • fdr
  • python
  • pandas
  • plotly
  • 웹 스크래핑
  • matplotlib
  • seaborn
hmin 댓글 0 좋아요 0 조회수 348

dict 수업중에 popitem이 임의의 값을 추출해온다고 하셨는데

미해결

프로그래밍 시작하기 : 파이썬 입문 (Inflearn Original)

리스트 수업에서였나 pop 값이 맨 뒤의 결과값을 빼낸다고 이해했는데 popitem은 임의의 값을 꺼내온다고 하셔서요 몇번 돌려봐도 임의의 값이 아니라 맨 뒤의 결과값이 꺼내져오는것같은데 혹시 제가 이해를 잘못했을까요? 아니면 프로그램의 결과값이 우연의 일치로 그런걸까요ㅠㅠ??

  • Chapter03_05
  • dict
  • python
  • popitem
나혜영 댓글 1 좋아요 0 조회수 344

인기 태그

인프런 TOP Writers

주간 인기글