Collecting yfinance
Downloading yfinance-0.1.63.tar.gz (26 kB)
Requirement already satisfied: pandas>=0.24 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.1.5)
Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.19.5)
Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.7/dist-packages (from yfinance) (2.23.0)
Requirement already satisfied: multitasking>=0.0.7 in /usr/local/lib/python3.7/dist-packages (from yfinance) (0.0.9)
Collecting lxml>=4.5.1
Downloading lxml-4.6.3-cp37-cp37m-manylinux2014_x86_64.whl (6.3 MB)
[K |████████████████████████████████| 6.3 MB 16.3 MB/s
[?25hRequirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24->yfinance) (2.8.2)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24->yfinance) (2018.9)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=0.24->yfinance) (1.15.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (2021.5.30)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (1.24.3)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (2.10)
Building wheels for collected packages: yfinance
Building wheel for yfinance (setup.py) ... [?25l[?25hdone
Created wheel for yfinance: filename=yfinance-0.1.63-py2.py3-none-any.whl size=23918 sha256=493432dc80209ff2b0e51db0bd76b98443dce0d6dc35edd47ee070faf2cce10a
Stored in directory: /root/.cache/pip/wheels/fe/87/8b/7ec24486e001d3926537f5f7801f57a74d181be25b11157983
Successfully built yfinance
Installing collected packages: lxml, yfinance
Attempting uninstall: lxml
Found existing installation: lxml 4.2.6
Uninstalling lxml-4.2.6:
Successfully uninstalled lxml-4.2.6
Successfully installed lxml-4.6.3 yfinance-0.1.63
Mounted at /content/drive
1.1 코딩의 주된 목적 == ‘자동화’
Automation
내가 하기 싫은 일을 남이(기계가) 대신하게 한다
프로그래밍을 잘 한다는 것?
기계가 잘 알아듣게 이야기 한다(프로그래밍 언어 라 불리는 EU)
고급 수준의 프로그래머라면?
기계가 고급진(부가가치가 높은)일을 잘 하게 할 수 있다
영어를 잘 하려면 미국에 가서 영어로 의사소통을 많이 해야 하고,
프로그래밍을 잘 하려면 일단 컴퓨터를 켜서, 프로그래밍을 많이 해봐야 한다.
당연히 시키는 일과 관련한 배경지식도 필수
일을 잘 아는 사람이 사람이 잘 시킨다
결국 세상은 남에게 일을 시킬 수 있는 사람과 남이 시키는 일만 할 수 있는 사람으로 양극화 된다.
프로그래밍을 할 줄 알아야 일을 시키며 살 수 있다.
시키는 일만 하면 되는 업무는 앞으로 AI가 대체할 가능성이 높다.
1.2 자동화의 예시 1 - 코스피 종가 데이터 자동으로 가져와 그래프 그리기
from matplotlib import pyplot as plt
import yfinance as yf
# KOSPI 일별 Adjusted Close. 첫 실행에는 인터넷 연결이 필요합니다.
df = yf.download("^KS11", period="5y", auto_adjust=False,
multi_level_index=False, progress=False)
if df.empty:
raise RuntimeError("KOSPI 데이터를 받지 못했습니다. 네트워크 연결을 확인한 뒤 다시 실행하세요.")
y_values = df['Adj Close']
x_values = range(len(y_values))
plt.plot(x_values, y_values)
plt.show()
[*********************100%***********************] 1 of 1 completed
<Figure size 432x288 with 1 Axes>
몇 줄의 스크립트로 이런 자동화가 가능하다.
1.3 자동화의 예시 2 - 뉴스 헤드라인 뉴스 자동으로 가져오기
import urllib.request
import xml.etree.ElementTree as ET
feed_url = 'https://www.yna.co.kr/rss/news.xml'
with urllib.request.urlopen(feed_url, timeout=15) as response:
feed = ET.fromstring(response.read())
headlines = [item.findtext('title', default='').strip()
for item in feed.findall('./channel/item')[:20]]
for title in headlines:
print(title)