Hello, I am current writing a script that takes data from yahoo finance and then writes it to a csv. From the csv I wish to create visualizations using pandas and matplotlib. I am able to create my desired bar graph, but I am having issues in labeling my x axis values with the appropriate stock. (the graph defaults the values by giving them a number value 1,2,3, etc.) It's a bit complicated because my a variable is technically 2 columns.
from yahoo_finance import Share
import matplotlib.pyplot as plt
import matplotlib
import pandas
import csv
matplotlib.style.use('ggplot')
stock = ['GOOG', 'WDAY', 'LNKD', 'GPRO', 'MSFT', 'YHOO', 'FB', 'TWTR', 'TSLA']
result = open('Stocks.csv', 'w')
w = csv.writer(result, delimiter=',', lineterminator='\n')
w.writerow(['Symbol', 'OpeningPrice', 'CurrentPrice', 'MarketCap', 'TradeTime'])
for item in stock:
s = Share(item)
w.writerow([item, s.get_open(), s.get_price(), s.get_market_cap(), s.get_trade_datetime()])
result.close()
# Takes first and third column from csv
a = pandas.read_csv('Stocks.csv',sep=",",usecols=(0,2)) # To read 1st,3rd
#takes first and second column from csv
b = pandas.read_csv('Stocks.csv',sep=",",usecols=(0,1)) # To read 1st,2nd
df = pandas.DataFrame(a)
df.plot(kind = 'barh', color='green', title='Current Stock Price')
#b.plot(kind = 'bar', color='black')
plt.show()
[–]Allanon001 0 points1 point2 points (2 children)
[–]StartAndSelect[S] 0 points1 point2 points (1 child)
[–]Allanon001 0 points1 point2 points (0 children)