Pandas yahoo finance DataReader

后端 未结 8 734
温柔的废话
温柔的废话 2020-12-24 09:36

I am trying to get the Adj Close prices from Yahoo Finance into a DataFrame. I have all the stocks I want but I am not able to sort on date.

stocks = [\'ORCL         


        
相关标签:
8条回答
  • 2020-12-24 10:14
    import pandas_datareader.data as web
    import datetime    
    
    start = datetime.datetime(2013, 1, 1)
    end = datetime.datetime(2016, 1, 27)
    df = web.DataReader("GOOGL", 'yahoo', start, end)
    
    dates =[]
    for x in range(len(df)):
        newdate = str(df.index[x])
        newdate = newdate[0:10]
        dates.append(newdate)
    
    df['dates'] = dates
    
    print df.head()
    print df.tail()
    
    0 讨论(0)
  • 2020-12-24 10:18

    Use dataFrame.index to directly access date or to add an explicit column, use dataFrame["Date"] = dataframe.index

    stocks = ['ORCL', 'TSLA', 'IBM','YELP', 'MSFT']
    ls_key = 'Adj Close'
    start = datetime(2014,1,1)
    end = datetime(2014,3,28)    
    f = web.DataReader(stocks, 'yahoo',start,end)
    
    
    cleanData = f.ix[ls_key]
    dataFrame = pd.DataFrame(cleanData)
    dataFrame["Date"] = dataframe.index
    print dataFrame["Date"] ## or print dataFrame.index
    
    0 讨论(0)
提交回复
热议问题