• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

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

22.07.14 14:25 작성 조회수 202

0

배운걸 활용해 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 사이 종가데이터가 없는 종목이 있어서 그런건가요?

 

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!