Get stock price with Python

While studying Python, there was a module that seemed to be interesting, so I tried using it

Things necessary

pandas_datareader

You can install it with the following code pip install pandas-datarader

Main subject

This time I got the stock price of a company called GAFA Please search Yahoo Finance for other stocks.

read-stock


import pandas_datareader as web
import pandas as pd
import datetime
data=web.get_data_yahoo(['GOOG','AAPL','FB','AMZN'])['Adj Close']

print(data.pct_change().tail())

Output example

Symbols         GOOG      AAPL        FB      AMZN
Date
2020-09-04 -0.030941  0.000662 -0.028820 -0.021787
2020-09-08 -0.036863 -0.067295 -0.040922 -0.043944
2020-09-09  0.016034  0.039887  0.009441  0.037707
2020-09-10 -0.016018 -0.032646 -0.020568 -0.028605
2020-09-11 -0.007376 -0.013129 -0.005521 -0.018547

Simple ~~ Explanation ~~ data: Adjusted closing price of each stock (Adj Close) pct_change (): Method to find the amount of change tail (): Get the last 5 rows of DataFrame

datetime


#If you want to decide the acquisition period
data=web,get_data_yahoo(['GOOG','AAPL','FB','AMZN'],
                        start=datetime.datetime(20xx,yy,zz),
                        end=datetime.datetime(20xx,yy,zz))['Adj Close']

Besides Open: Open price Close: Close price High: High Low: Low price Volume: Volume And so on

Recommended Posts

Get stock price with Python
Get date with python
Get US stock price from Python with Web API with Raspberry Pi
Let's do web scraping with Python (stock price)
Get country code with python
Get Twitter timeline with python
Get Youtube data with python
Stock price forecast with tensorflow
Get thread ID with python
Python: Stock Price Forecast Part 2
Get started with Python! ~ ② Grammar ~
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
Python: Stock Price Forecast Part 1
[Time series with plotly] Dynamic visualization with plotly [python, stock price]
Get the stock price of a Japanese company with Python and make a graph
Get started with Python! ~ ① Environment construction ~
Get reviews with python googlemap api
Get the weather with Python requests
Get web screen capture with python
Get the weather with Python requests 2
[Python] Get economic data with DataReader
[Python] My stock price forecast [HFT]
How to get started with Python
[Small story] Get timestamp with Python
Get Qiita trends with Python scraping
Get started with Python in Blender
Get weather information with Python & scraping
Programming history 1 month Extract NY Dow stock price with Python!
Get Japanese stock price information from yahoo finance with pandas
Get additional data in LDAP with python
Get property information by scraping with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Statistics with python
Python with Go
[Python] Get the variable name with str
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Check stock prices with slackbot using python
Tested with Python
python starts with ()
Web scraping with Python ② (Actually scraping stock sites)
with syntax (Python)
Get Started with TopCoder in Python (2020 Edition)
Stock Price Forecast with TensorFlow (LSTM) ~ Stock Forecast Part 1 ~
[Python] Creating a stock price drawdown chart
Bingo with python
Zundokokiyoshi with python
[Python] Get Python package information with PyPI API
How Python beginners get started with Python with Progete
Let's get along with Python # 0 (Environment construction)
Excel with Python
Microcomputer with Python
[Blender x Python] Let's get started with Blender Python !!
Cast with python
Python hand play (let's get started with AtCoder?)
Stock number ranking by Qiita tag with python