개발/python

파이썬 - pandas LG전자 일봉가져오기

xwing 2020. 12. 29. 21:00

python & pandas 를 통해서

요즘 주식이 매우매우 상승세를 타고있는 LG전자와 삼성전자의 일봉을 가져와서 표시해봅시다.
 (LG전자를 파는게 아니였어 ㅠㅠ)

Request 객체를 통해서 가져오는 것보다 훨씬 간단하게 가져와 표시할 수 있다.

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()
view raw pandas_yahoo.py hosted with ❤ by GitHub

끝~

반응형

'개발 > python' 카테고리의 다른 글

[python 기초] 엑셀에 구구단 출력하기  (0) 2021.01.05
yahoo finance 크롤링  (0) 2020.12.19
python - 다음 일봉 크롤링  (0) 2020.12.19