python & pandas 를 통해서
요즘 주식이 매우매우 상승세를 타고있는 LG전자와 삼성전자의 일봉을 가져와서 표시해봅시다.
(LG전자를 파는게 아니였어 ㅠㅠ)
Request 객체를 통해서 가져오는 것보다 훨씬 간단하게 가져와 표시할 수 있다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pandas_datareader.data as web | |
import matplotlib.pyplot as plt | |
from datetime import datetime | |
start = datetime(2020, 1, 1) | |
end = datetime.now() | |
lg = web.DataReader("066570.KS", "yahoo", start, end) | |
samsung = web.DataReader("005930.KS", "yahoo", start, end) | |
plt.figure(figsize=(10,5)) | |
plt.plot(lg.index, lg['Adj Close'], label='LG Electronics') | |
plt.plot(samsung.index, samsung['Adj Close'], label='Samsung Electronics') | |
plt.title("LGE - SAMSUNG") | |
plt.grid(True) | |
plt.legend(loc='upper left') | |
#change background-color | |
ax = plt.axes() | |
ax.set_facecolor("grey") | |
plt.show() |

끝~
반응형
'개발 > python' 카테고리의 다른 글
[python 기초] 엑셀에 구구단 출력하기 (0) | 2021.01.05 |
---|---|
yahoo finance 크롤링 (0) | 2020.12.19 |
python - 다음 일봉 크롤링 (0) | 2020.12.19 |