pip install pandas
pip install pandas-datareader
First, we need to import the packages and modules.
import pandas as pd
from pandas_datareader import data
import matplotlib.pyplot as plt
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
Now we define the company we want to look at through their associated shortcut and we set the starting date and the ending date.
symbol = 'NFLX'
data_source = 'yahoo'
start_date = '2020-01-01'
end_date = '2020-09-30'
We now try to extract the data from the yahoo finance website.
df = data.get_data_yahoo(symbol, start_date, end_date)
df.index = pd.to_datetime(df.index)
print(type(df.index))
We now check if there are some null values.
print(df.isnull().sum())
Fortunately, there are no null values. We now can plot a graph that shows us our extracted data.
fig, ax = plt.subplots(figsize=(12, 6))
ax.plot_date(x= df.index, y = df['Adj Close'], fmt='-')
fig.suptitle('NFLX')
plt.show()