Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import pandas_datareader.data as web
  2. import matplotlib.pyplot as plt
  3. from matplotlib import style
  4. import datetime as dt
  5.  
  6. style.use('ggplot')
  7.  
  8. # The goal here was to get practice getting data from a website and printing a graph with that data
  9.  
  10. # Arbitrary date range, could easily be modified to accept user input
  11. start = dt.datetime(2006, 1, 1)
  12. end = dt.datetime(2016, 12, 31)
  13.  
  14. # Ask User to specify which stock ticker to check
  15. stock_to_check = input("Enter a ticker symbol: ")
  16.  
  17. # Request data from website (I have been using get.requests() for webscraping but this seems to be easier for my purposes
  18. df = web.DataReader(stock_to_check, 'yahoo', start, end)
  19.  
  20. # Print off just the first and last 3 lines
  21. print(df.head(3))
  22. print(df.tail(3))
  23.  
  24. plt.plot(df['Adj Close'])
  25. plt.ylabel('price')
  26.  
  27. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement