[IBM] Python Project for Data Science - Extracting Stock Data Using a Python Library
2021. 5. 11. 22:57ㆍData science/Python
반응형
I have watched the first 2 videos from the previous course. So I skipped them and went for the project directly.
Final Project: Analyzing Stock Performance and Building a Dashboard
- extract financial data like historical share price, quarterly revenue reporting
- web scraping on popular stocks
- Visualize in a dashboard to identify the patterns or trends
#install the yfinace and import yfinance and pandas
#yfinance: extract the stock data
!pip install yfinance
import yfinance as yf
import pandas as pd
#Ticker module: create an object to access fuctions to extract data .Ticker("ticker symbol")
apple = yf.Ticket("AAPL")
#info: extract information about the stock as a Python Dictionary
appple_info=apple.info
apple_info
#Get the specific information by using key
apple_info['country']
#result would be
'United States'
#Using History() method to get the share price over a certain period of time
#The options for period are 1 day (1d), 5d, 1 month (1mo) , 3mo, 6mo, 1 year (1y), 2y, 5y, 10y, ytd, and max.
apple_share_price_data = apple.history(period="max")
#to get the max of certain columns (Max values of the Volume column)
apple_share_price_data.Volume.max()
#Reset and store into the dataFrame itself
apple_share_price_data.reset_index(inplace=True)
#Plot the open price against the date
apple_share_price_data.plot(x="Date", y="Open")
#Get the dividends: apple.dividends / plot: apple.dividends.plot()
https://gist.github.com/1fef82695ecf4e71ab99d1c13f209bab
Created on Skills Network Labs
Created on Skills Network Labs. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
반응형