데이터 전체에 대한 수익률을 계산하고 싶은데 오류가 뜹니다
324
3 asked
배운걸 활용해 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 사이 종가데이터가 없는 종목이 있어서 그런건가요?
Answer 0
cufflinks 버전문제로 iplot() 미실행
0
42
2
[수정요청]직접 수집한 주가 데이터로 시각화해보기
0
52
2
pd.read_html(url, encoding='cp949') 에러
0
75
2
fdr.StockListing('KRX') 문제 발생
0
137
2
주식 자동매매 프로그램 제작 관련 조언 부탁드립니다
0
430
1
concat 을 통한 데이터 프레임 합치기 에러 문의
0
104
2
한글폰트 관련해서 문의드립니다.
0
230
2
데이터프레임 칼럼명 문의 드립니다.
0
239
3
금융데이터 수집의 모든것
0
145
2
녹화시점과 현재시점 컬럼명이 변경이 많이 되었을까요?
0
191
2
파이썬 증권 데이터 수집과 분석으로 신호와 소음 찾기 - 섹션1 [2/2]
0
173
1
Mac 환경에서 nbextensions 활성화 하는 방법
0
594
2
pd.concat(result.tolist()) 오류 문의
0
244
1
5.1 제약 데이터 수집 오류 해결
0
231
1
Table of contents 문의드립니다
0
209
2
concat을 통한 데이터프레임 합치기
0
548
2
Reindexing only valid with uniquely valued Index objects 오류 질문입니다.
0
491
1
데이터 비교시 데이터 불일치
0
410
1
dtype={"itemcode": np.object}) 을 dtype={"itemcode": object}) 으로 변경해야 하나요?
0
593
1
질문 : for문 풀어쓰기
0
488
1
파이참에서 Plotly 그래프 실행방법
0
1308
1
5.1 데이터프레임 병합(merge)
0
741
2
쥬피터노트북에서 실행파일 만들기
0
1449
1
주피터노트북 확장팩 설치가 안됩니다.
0
562
2

