Collecting yfinance
Downloading yfinance-0.1.70-py2.py3-none-any.whl (26 kB)
Requirement already satisfied: multitasking>=0.0.7 in /usr/local/lib/python3.7/dist-packages (from yfinance) (0.0.10)
Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.21.5)
Requirement already satisfied: pandas>=0.24.0 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.3.5)
Collecting lxml>=4.5.1
Downloading lxml-4.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.4 MB)
[K |████████████████████████████████| 6.4 MB 7.2 MB/s
[?25hCollecting requests>=2.26
Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
[K |████████████████████████████████| 63 kB 1.5 MB/s
[?25hRequirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24.0->yfinance) (2018.9)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24.0->yfinance) (2.8.2)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas>=0.24.0->yfinance) (1.15.0)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (2021.10.8)
Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (2.0.12)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.26->yfinance) (1.24.3)
Installing collected packages: requests, lxml, yfinance
Attempting uninstall: requests
Found existing installation: requests 2.23.0
Uninstalling requests-2.23.0:
Successfully uninstalled requests-2.23.0
Attempting uninstall: lxml
Found existing installation: lxml 4.2.6
Uninstalling lxml-4.2.6:
Successfully uninstalled lxml-4.2.6
[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
google-colab 1.0.0 requires requests~=2.23.0, but you have requests 2.27.1 which is incompatible.
datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible.[0m
Successfully installed lxml-4.8.0 requests-2.27.1 yfinance-0.1.70
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)