Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Step 1
- import pandas as pd
- from matplotlib import pyplot as plt
- import seaborn as sns
- # Step 2
- netflix_stocks = pd.read_csv("NFLX.csv")
- #print(netflix_stocks.head())
- dowjones_stocks = pd.read_csv("DJI.csv")
- #print(dowjones_stocks.head())
- netflix_stocks_quarterly = pd.read_csv("NFLX_daily_by_quarter.csv")
- #print(netflix_stocks_quarterly.head())
- #Step 3
- # Some questions to answer
- #Step 4
- netflix_stocks.rename(columns = {
- "Adj Close": "Price"
- }, inplace = True)
- print(netflix_stocks.head())
- dowjones_stocks.rename(columns = {
- "Adj Close": "Price"
- }, inplace = True)
- print(dowjones_stocks.head())
- netflix_stocks_quarterly.rename(columns = {
- "Adj Close": "Price"
- }, inplace = True)
- print(netflix_stocks_quarterly.head())
- # Step 5
- ax = sns.violinplot(
- data = netflix_stocks_quarterly,
- x = "Quarter",
- y = "Price")
- ax.set_title("Distribution of 2017 Netflix Stock Prices by Quarter")
- ax.set_ylabel("Closing Stock Prices")
- ax.set_xlabel("Business Quarters in 2017")
- plt.show()
- plt.savefig("Netflix Price per Quarter")
- # Step 6
- 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_positions, earnings_actual, color = 'red', alpha = 0.5)
- plt.scatter(x_positions, earnings_estimate, color = 'blue', alpha =0.5)
- plt.legend(["Actual", "Estimate"])
- plt.xticks(x_positions, chart_labels)
- plt.xlabel("Quarter of the Year")
- plt.ylabel("Money")
- plt.title("Earning per share in cent")
- plt.show()
- plt.savefig("Eaning per share")
- # Step 7
- # 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 = 0.5 # Width of each bar
- bars1_x = [t*element + w*n for element
- in range(d)]
- plt.bar(bars1_x,revenue_by_quarter)
- # Earnings
- n = 2 # This is our second dataset (out of 2)
- t = 2 # Number of dataset
- d = 4 # Number of sets of bars
- w = 0.5 # Width of each bar
- bars2_x = [t*element + w*n for element
- in range(d)]
- plt.bar(bars2_x,earnings_by_quarter)
- middle_x = [ (a + b) / 2.0 for a, b in zip(bars1_x, bars2_x)]
- plt.xticks(middle_x, quarter_labels)
- labels = ["Revenue", "Earnings"]
- plt.legend(labels)
- plt.title ("Earnings and Revenue per Quarter in Netflix")
- plt.xlabel("Quarter of the Year")
- plt.ylabel ("Money (in billion dollars)")
- plt.show()
- plt.savefig("Earning and Revenue")
- # Step 8
- date = netflix_stocks.Date
- netflix_price = netflix_stocks.Price
- dowjones_price = dowjones_stocks.Price
- ax1 = plt.subplot(1,2,1)
- plt.plot(date, netflix_price,color = 'red' , marker = 'o')
- plt.title("Netflix")
- plt.xlabel("Date")
- plt.xticks(rotation = 75)
- plt.ylabel("Stock Price")
- ax2 = plt.subplot(1,2,2)
- plt.plot(date, dowjones_price, color= 'green' , marker = 'o')
- plt.title("Dow Jones")
- plt.xlabel("Date")
- plt.xticks(rotation = 75)
- plt.ylabel("Stock Price")
- plt.subplots_adjust(wspace=.5)
- plt.show()
- plt.savefig("Netflix vs Dow Jones")
Add Comment
Please, Sign In to add comment