Netflix Data Visualization Capstone Project

Hello, please review the presentation and the script for the project below:

Presentation link

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns

netflix_stocks = pd.read_csv('NFLX.csv')

dowjones_stocks = pd.read_csv('DJI.csv')

netflix_stocks_quarterly = pd.read_csv('NFLX_daily_by_quarter.csv')

# What year is represented in the data? Look out for the latest and earliest date.

print('- 2017')

#  Is the data represented by days, weeks, or months? 
#  In which ways are the files different? 
#  What's different about the columns for `netflix_stocks` versus `netflix_stocks_quarterly`?

print('- Netflix_stocks and dowjones_stocks have the same columns and number of rows (with data stored at the monthly grain at the beginning of each month), while netflix_stocks_quarterly has data stored at the daily level')
# Great! Now that we have spent sometime looking at the data, let's look at the column names of the DataFrame `netflix_stocks` using `.head()`. 


# What do you notice? The first two column names are one word each, and the only one that is not is `Adj Close`! 
# The term `Adj Close` is a confusing term if you don't read the Yahoo Documentation. In Yahoo, `Adj Close` is documented as adjusted close price adjusted for both dividends and splits.
# This means this is the column with the true closing price, so these data are very important.
# Use Pandas to change the name of of the column to `Adj Close` to `Price` so that it is easier to work with the data. Remember to use `inplace=True`.
# Do this for the Dow Jones and Netflix Quarterly pandas dataframes as well.
# Hint: Use [`.rename()`](

new_name = {'Adj Close': 'Price'}
netflix_stocks.rename(columns=new_name, inplace=True)
dowjones_stocks.rename(columns=new_name, inplace=True)
netflix_stocks_quarterly.rename(columns=new_name, inplace=True)

# Run `netflix_stocks.head()` again to check your column name has changed.


# Call `.head()` on the DataFrame `dowjones_stocks` and `netflix_stocks_quarterly`.


# ## Step 5
# In this step, we will be visualizing the Netflix quarterly data! 
# We want to get an understanding of the distribution of the Netflix quarterly stock prices for 2017. Specifically, we want to see in which quarter stock prices flucutated the most. We can accomplish this using a violin plot with four violins, one for each business quarter!
# 1. Start by creating a variable `ax` and setting it equal to `sns.violinplot()`. This will instantiate a figure and give us access to the axes through the variable name `ax`.
# 2. Use `sns.violinplot()` and pass in the following arguments:
# + The `Quarter` column as the `x` values
# + The `Price` column as your `y` values
# + The `netflix_stocks_quarterly` dataframe as your `data`
# 3. Improve the readability of the chart by adding a title of the plot. Add `"Distribution of 2017 Netflix Stock Prices by Quarter"` by using `ax.set_title()`
# 4. Change your `ylabel` to "Closing Stock Price"
# 5. Change your `xlabel` to "Business Quarters in 2017"
# 6. Be sure to show your plot!

ax = sns.violinplot()
sns.violinplot(data=netflix_stocks_quarterly, x='Quarter', y='Price')
ax.set_xlabel('Buisiness Quarters in 2017')
ax.set_ylabel('Closing Stock Price')
ax.set_title('Distribution of 2017 Netflix Stock Prices by Quarter')

# ## Graph Literacy
# - What are your first impressions looking at the visualized data?
# - In what range(s) did most of the prices fall throughout the year?
# - What were the highest and lowest prices? 

print('- Q3 has the most dispersed distribution')
print('- Most prices were between 140 and 200')
print('- Lowest price was around 120, the highest above 200')

# ## Step 6
# Next, we will chart the performance of the earnings per share (EPS) by graphing the estimate Yahoo projected for the Quarter compared to the actual earnings for that quarters. We will accomplish this using a scatter chart. 
# 1. Plot the actual EPS by using `x_positions` and `earnings_actual` with the `plt.scatter()` function. Assign `red` as the color.
# 2. Plot the actual EPS by using `x_positions` and `earnings_estimate` with the `plt.scatter()` function. Assign `blue` as the color
# 3. Often, estimates and actual EPS are the same. To account for this, be sure to set your transparency  `alpha=0.5` to allow for visibility pf overlapping datapoint.
# 4. Add a legend by using `plt.legend()` and passing in a list with two strings `["Actual", "Estimate"]`
# 5. Change the `x_ticks` label to reflect each quarter by using `plt.xticks(x_positions, chart_labels)`
# 6. Assing "`"Earnings Per Share in Cents"` as the title of your plot.

x_positions = [1, 2, 3, 4]
chart_labels = ["1Q2017","2Q2017","3Q2017","4Q2017"]
earnings_actual =[.4, .15,.29,.41]
earnings_estimate = [.37,.15,.32,.41 ]
plt.scatter(x=x_positions, y=earnings_actual, color='red', marker='o', alpha=.5)
plt.scatter(x=x_positions, y=earnings_estimate, color='blue', marker='x', alpha=.5)
plt.legend(['Actual', 'Estimate'], loc=4)
plt.xticks(ticks=x_positions, labels=chart_labels)
plt.title('Earnings per Share in Cents')

# ## Graph Literacy
# + What do the purple dots tell us about the actual and estimate earnings per share in this graph? Hint: In color theory red and blue mix to make purple.

print('The estimates were spot on the actual EPS')

# ## Step 7
# Next, we will visualize the earnings and revenue reported by Netflix by mapping two bars side-by-side. We have visualized a similar chart in the second Matplotlib lesson [Exercise 4](
# As you may recall, plotting side-by-side bars in Matplotlib requires computing the width of each bar before hand. We have pasted the starter code for that exercise below. 
# 1. Fill in the `n`, `t`, `d`, `w` values for the revenue bars
# 2. Plot the revenue bars by calling `` with the newly computed `x_values` and the `revenue_by_quarter` data
# 3. Fill in the `n`, `t`, `d`, `w` values for the earnings bars
# 4. Plot the revenue bars by calling `` with the newly computed `x_values` and the `earnings_by_quarter` data
# 5. Create a legend for your bar chart with the `labels` provided
# 6. Add a descriptive title for your chart with `plt.title()`
# 7. Add labels to each quarter by assigning the position of the ticks through the code provided. Hint:  `plt.xticks(middle_x, quarter_labels)`
# 8. Be sure to show your plot!

# The metrics below are in billions of dollars
revenue_by_quarter = [2.79, 2.98,3.29,3.7]
earnings_by_quarter = [.0656,.12959,.18552,.29012]
quarter_labels = ["2Q2017","3Q2017","4Q2017", "1Q2018"]

# Revenue
n = 1  # This is our first dataset (out of 2)
t = 2 # Number of dataset
d = 4 # Number of sets of bars
w = .8 # Width of each bar
bars1_x = [t*element + w*n for element
             in range(d)]

# Earnings
n = 2  # This is our second dataset (out of 2)
t = 2 # Number of dataset
d = 4 # Number of sets of bars
w = .8 # Width of each bar
bars2_x = [t*element + w*n for element
             in range(d)]

middle_x = [ (a + b) / 2.0 for a, b in zip(bars1_x, bars2_x)]
labels = ["Revenue", "Earnings"], revenue_by_quarter, color='green'), earnings_by_quarter, color='purple')
plt.xticks(ticks=middle_x, labels=quarter_labels)
plt.title('Earnings vs Revenue per Quarter')

# ## Graph Literacy
# What are your first impressions looking at the visualized data?
# - Does Revenue follow a trend?
# - Do Earnings follow a trend?
# - Roughly, what percentage of the revenue constitutes earnings?

print('- Earnings are significantly lower than posted revenue')
print('- Both revenue and earnings increase over time')
print('- Earnings appear to be roughly 10 percent of revenue')

# ## Step 8
# In this last step, we will compare Netflix stock to the Dow Jones Industrial Average in 2017. We will accomplish this by plotting two line charts side by side in one figure. 
# Since `Price` which is the most relevant data is in the Y axis, let's map our subplots to align vertically side by side.
# - We have set up the code for you on line 1 in the cell below. Complete the figure by passing the following arguments to `plt.subplots()` for the first plot, and tweaking the third argument for the second plot
#     - `1`-- the number of rows for the subplots
#     - `2` -- the number of columns for the subplots
#     - `1` -- the subplot you are modifying
# - Chart the Netflix Stock Prices in the left-hand subplot. Using your data frame, access the `Date` and `Price` charts as the x and y axes respectively. Hint: (`netflix_stocks['Date'], netflix_stocks['Price']`)
# - Assign "Netflix" as a title to this subplot. Hint: `ax1.set_title()`
# - For each subplot, `set_xlabel` to `"Date"` and `set_ylabel` to `"Stock Price"`
# - Chart the Dow Jones Stock Prices in the left-hand subplot. Using your data frame, access the `Date` and `Price` charts as the x and y axes respectively. Hint: (`dowjones_stocks['Date'], dowjones_stocks['Price']`)
# - Assign "Dow Jones" as a title to this subplot. Hint: `plt.set_title()`
# - There is some crowding in the Y axis labels, add some space by calling `plt.subplots_adjust(wspace=.5)`
# - Be sure to `.show()` your plots.

# Left plot Netflix
ax1 = plt.subplot(1,2,1)
plt.plot(netflix_stocks['Date'], netflix_stocks['Price'], color='purple', marker='o')
ax1.set_ylabel('Stock Price')

# Right plot Dow Jones
ax2 = plt.subplot(1,2,2)
plt.plot(dowjones_stocks['Date'], dowjones_stocks['Price'], color='black', marker='o')
ax2.set_title('Dow Jones')
ax2.set_ylabel('Index Price')

# - How did Netflix perform relative to Dow Jones Industrial Average in 2017?
# - Which was more volatile?
# - How do the prices of the stocks compare?

print('- Netflix was more volatile, but its growth maintained a similar pace')
print('- Netflix')
print('- The price of the Dow Jones Industrial Average index is significantly higher than that of Netflix')

# # Step 9
# It's time to make your presentation! Save each of your visualizations as a png file with `plt.savefig("filename.png")`.
# As you prepare your slides, think about the answers to the graph literacy questions. Embed your observations in the narrative of your slideshow!
# Remember that your slideshow must include:
# - A title slide
# - A list of your visualizations and your role in their creation for the "Stock Profile" team
# - A visualization of the distribution of the stock prices for Netflix in 2017
# - A visualization and a summary of Netflix stock and revenue for the past four quarters and a summary
# - A visualization and a brief summary of their earned versus actual earnings per share
# - A visualization of Netflix stock against the Dow Jones stock (to get a sense of the market) in 2017

Thank you for your time!