Deb Deb - 1 year ago 191
Python Question

How to get only Adjusted Close Price from Yahoo Finance library

I am using the Yahoo Finance Library in Python to pull data of a stock.

import yahoo_finance
ticker = 'GLD'
begdate = '2014-11-11'
enddate = '2016-11-11'
data = yahoo_finance.Share('GLD')
data1 = data.get_historical(begdate,enddate)
gld_df = pd.DataFrame(data1)
date_df = (list(gld_df["Date"]))
adj_close_df = list(gld_df["Adj_Close"])


I would like to plot this Adjusted Close Price on Y-Axis and the corresponding Dates on the X Axis, but my above code is giving an error when I try to do that.

I am using Python 3.x, Anaconda

Answer Source

You could generate the list as below:

l = [ x['Close'] for x in data1]

And the plot:

import matplotlib.pyplot as plt
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download