Guest User

Untitled

a guest
Jun 29th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. # Step 1
  2.  
  3. import pandas as pd
  4. from matplotlib import pyplot as plt
  5. import seaborn as sns
  6.  
  7. # Step 2
  8. netflix_stocks = pd.read_csv("NFLX.csv")
  9. #print(netflix_stocks.head())
  10. dowjones_stocks = pd.read_csv("DJI.csv")
  11. #print(dowjones_stocks.head())
  12. netflix_stocks_quarterly = pd.read_csv("NFLX_daily_by_quarter.csv")
  13. #print(netflix_stocks_quarterly.head())
  14.  
  15. #Step 3
  16. # Some questions to answer
  17.  
  18. #Step 4
  19. netflix_stocks.rename(columns = {
  20. "Adj Close": "Price"
  21. }, inplace = True)
  22. print(netflix_stocks.head())
  23.  
  24. dowjones_stocks.rename(columns = {
  25. "Adj Close": "Price"
  26. }, inplace = True)
  27. print(dowjones_stocks.head())
  28.  
  29. netflix_stocks_quarterly.rename(columns = {
  30. "Adj Close": "Price"
  31. }, inplace = True)
  32. print(netflix_stocks_quarterly.head())
  33.  
  34. # Step 5
  35.  
  36. ax = sns.violinplot(
  37. data = netflix_stocks_quarterly,
  38. x = "Quarter",
  39. y = "Price")
  40. ax.set_title("Distribution of 2017 Netflix Stock Prices by Quarter")
  41. ax.set_ylabel("Closing Stock Prices")
  42. ax.set_xlabel("Business Quarters in 2017")
  43. plt.show()
  44. plt.savefig("Netflix Price per Quarter")
  45.  
  46. # Step 6
  47. x_positions = [1, 2, 3, 4]
  48. chart_labels = ["1Q2017","2Q2017","3Q2017","4Q2017"]
  49. earnings_actual =[.4, .15,.29,.41]
  50. earnings_estimate = [.37,.15,.32,.41 ]
  51. plt.scatter(x_positions, earnings_actual, color = 'red', alpha = 0.5)
  52. plt.scatter(x_positions, earnings_estimate, color = 'blue', alpha =0.5)
  53. plt.legend(["Actual", "Estimate"])
  54. plt.xticks(x_positions, chart_labels)
  55. plt.xlabel("Quarter of the Year")
  56. plt.ylabel("Money")
  57. plt.title("Earning per share in cent")
  58. plt.show()
  59. plt.savefig("Eaning per share")
  60. # Step 7
  61.  
  62. # The metrics below are in billions of dollars
  63. revenue_by_quarter = [2.79, 2.98,3.29,3.7]
  64. earnings_by_quarter = [.0656,.12959,.18552,.29012]
  65. quarter_labels = ["2Q2017","3Q2017","4Q2017", "1Q2018"]
  66.  
  67. # Revenue
  68. n = 1 # This is our first dataset (out of 2)
  69. t = 2 # Number of dataset
  70. d = 4 # Number of sets of bars
  71. w = 0.5 # Width of each bar
  72. bars1_x = [t*element + w*n for element
  73. in range(d)]
  74. plt.bar(bars1_x,revenue_by_quarter)
  75. # Earnings
  76. n = 2 # This is our second dataset (out of 2)
  77. t = 2 # Number of dataset
  78. d = 4 # Number of sets of bars
  79. w = 0.5 # Width of each bar
  80. bars2_x = [t*element + w*n for element
  81. in range(d)]
  82. plt.bar(bars2_x,earnings_by_quarter)
  83. middle_x = [ (a + b) / 2.0 for a, b in zip(bars1_x, bars2_x)]
  84. plt.xticks(middle_x, quarter_labels)
  85. labels = ["Revenue", "Earnings"]
  86. plt.legend(labels)
  87. plt.title ("Earnings and Revenue per Quarter in Netflix")
  88. plt.xlabel("Quarter of the Year")
  89. plt.ylabel ("Money (in billion dollars)")
  90. plt.show()
  91. plt.savefig("Earning and Revenue")
  92. # Step 8
  93. date = netflix_stocks.Date
  94. netflix_price = netflix_stocks.Price
  95. dowjones_price = dowjones_stocks.Price
  96. ax1 = plt.subplot(1,2,1)
  97. plt.plot(date, netflix_price,color = 'red' , marker = 'o')
  98. plt.title("Netflix")
  99. plt.xlabel("Date")
  100. plt.xticks(rotation = 75)
  101. plt.ylabel("Stock Price")
  102. ax2 = plt.subplot(1,2,2)
  103. plt.plot(date, dowjones_price, color= 'green' , marker = 'o')
  104. plt.title("Dow Jones")
  105. plt.xlabel("Date")
  106. plt.xticks(rotation = 75)
  107. plt.ylabel("Stock Price")
  108. plt.subplots_adjust(wspace=.5)
  109. plt.show()
  110. plt.savefig("Netflix vs Dow Jones")
Add Comment
Please, Sign In to add comment