Learn practical skills, build real-world projects, and advance your career
alt

Finance and Stocks with Pandas and Python

~ Evan Marie Carr (http://www.EvanMarie.com)

  • stockhelpers.py - custom functions used throughout this project

    This project is fairly long and covers a lot of ground. So in an effort to allow for the abstraction away of many repetitive functions and operations, I have compiled this helper file. For the functions that are necessary in understanding what is happening in the code, I include descriptions of each function as well as a link to the GitHub Gist for each individual function, in the following manner:

    🔗 stockhelpers.function_name() - GitHub Gist

    Other functions are just for the purpose of notebook presentation. The cell below downloads and imports the Python file, but you can investigate the functions on their own as well. All (any function within this notebook preceeded by h., my chosen alias for my helpers import) can be found here in one notebook as well.

%%capture
!pip install lxml
!pip install yfinance
import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.family'] = 'monospace'
%matplotlib inline
pd.options.display.float_format = '{:,.3f}'.format
from urllib.request import urlretrieve
url = "https://mydatabucky.s3.amazonaws.com/stockhelpers.py"
urlretrieve(url, "stockhelpers.py")
import stockhelpers as h

🔷 Importing & Inspecting Dow Jones Index Data from Wikipedia

alt
dj_wiki = pd.read_html("https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average")[1]

dj_wiki = dj_wiki.iloc[:, :5].copy()

dj_wiki.rename(columns = {'Company': 'company', 'Exchange': 'exchange', 'Symbol': 'symbol', 'Industry': 'industry', 'Date added': 'date_added'}, inplace = True)

dj_wiki.date_added = pd.to_datetime(dj_wiki.date_added)