라이브러리 설치
pip install -U finance-datareader
코드 입력
import FinanceDataReader as fdr
df_krx = fdr.StockListing('KRX')
df_kospi = fdr.StockListing('KOSPI')
df_kosdoq = fdr.StockListing('KOSDAQ')
df_konex = fdr.StockListing('KONEX')
print('krx count :', df_krx['Symbol'].count())
print('kospi count :', df_kospi['Symbol'].count())
print('kosdoq count :', df_kosdoq['Symbol'].count())
print('konex count :', df_konex['Symbol'].count())
exit()
출력 결과
코드 입력
import FinanceDataReader as fdr
df_krx = fdr.StockListing('KRX')
df_kospi = fdr.StockListing('KOSPI')
df_kosdoq = fdr.StockListing('KOSDAQ')
df_konex = fdr.StockListing('KONEX')
print('krx count :', df_krx['Symbol'].count())
print('kospi count :', df_kospi['Symbol'].count())
print('kosdoq count :', df_kosdoq['Symbol'].count())
print('konex count :', df_konex['Symbol'].count())
print('----------------------------')
print('krx columns :', df_krx.columns)
print('kospi columns :', df_kospi.columns)
print('kosdoq columns :', df_kosdoq.columns)
print('konex columns :', df_konex.columns)
exit()
출력 결과
특정 주식이 어디에 있는지 확인하기
import FinanceDataReader as fdr
df_krx = fdr.StockListing('KRX')
df_kospi = fdr.StockListing('KOSPI')
df_kosdoq = fdr.StockListing('KOSDAQ')
df_konex = fdr.StockListing('KONEX')
search_name = '삼성전자'
if (df_krx['Name'] == search_name).any(): print('KRX')
if (df_kospi['Name'] == search_name).any(): print('KOSPI')
if (df_kosdoq['Name'] == search_name).any(): print('KOSDAQ')
if (df_konex['Name'] == search_name).any(): print('KONEX')
exit()
특정 주식의 코드 확인하기
import FinanceDataReader as fdr
# df_krx = fdr.StockListing('KRX')
df_kospi = fdr.StockListing('KOSPI')
# df_kosdoq = fdr.StockListing('KOSDAQ')
# df_konex = fdr.StockListing('KONEX')
search_name = '삼성전자'
search_code = df_kospi[df_kospi['Name'] == search_name]['Symbol']
print(search_code)
exit()
주식코드를 이용한 주식가격 조회
import FinanceDataReader as fdr
# df_krx = fdr.StockListing('KRX')
df_kospi = fdr.StockListing('KOSPI')
# df_kosdoq = fdr.StockListing('KOSDAQ')
# df_konex = fdr.StockListing('KONEX')
search_name = '삼성전자'
# search_code = df_kospi[df_kospi['Name'] == search_name]['Symbol']
df = fdr.DataReader('005930', '2022-08-16', '2022-08-23')
print(df)
exit()
컬럼명 변경
import FinanceDataReader as fdr
# df_krx = fdr.StockListing('KRX')
# df_kospi = fdr.StockListing('KOSPI')
# df_kosdoq = fdr.StockListing('KOSDAQ')
# df_konex = fdr.StockListing('KONEX')
search_name = '삼성전자'
# search_code = df_kospi[df_kospi['Name'] == search_name]['Symbol']
df = fdr.DataReader('005930', '2022-08-16', '2022-08-23')
df.rename(columns = {'Open': '시가', 'High': '고가', 'Low': '저가', 'Close': '종가', 'Volume': '거래량', 'Change': '변화율'}, inplace = True)
print(df)
exit()
'Programming Language > Python' 카테고리의 다른 글
[Python] 컴파일언어, 스크립트언어 란? (0) | 2022.08.28 |
---|---|
[Python] pip 란? (0) | 2022.08.28 |
[Python] 문자열을 hash 값으로 만드는 방법 (0) | 2022.08.07 |
[Python] 리스트 여러개를 판다스 데이터프레임으로 만드는 방법 (0) | 2022.08.07 |
아나콘다 사용시 가상환경 만들기 삭제 명령어 모음 (0) | 2022.08.07 |