Pandas yahoo finance DataReader

后端 未结 8 730
温柔的废话
温柔的废话 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 09:52

    Date is in the index values.

    To get it into a column value, you should just use:

    dataframe.reset_index(inplace=True,drop=False)
    

    Then you can use

    dataframe['Date'] 
    

    because "Date" will now be one of the keys in your columns of the dataframe.

    0 讨论(0)
  • 2020-12-24 09:58

    The sub-package pandas.io.data is removed from the latest pandas package and it is available to install separately as pandas-datareader

    use git to install the package. in the linux terminal:

    git clone https://github.com/pydata/pandas-datareader.git
    cd pandas-datareader
    python setup.py install
    

    now you can use import pandas_datareader to your python script for Remote data Access.

    For more information Use this link to visit the latest documentation

    0 讨论(0)
  • 2020-12-24 10:04

    f is a Panel You can get a DataFrame and reset index (Date) using:

    f.loc['Adj Close',:,:].reset_index()
    

    but I'm not sure reset_index() is very useful as you can get Date using

    f.loc['Adj Close',:,:].index
    

    You might have a look at http://pandas.pydata.org/pandas-docs/stable/indexing.html#different-choices-for-indexing about indexing

    0 讨论(0)
  • 2020-12-24 10:07

    print(dataFrame.index[0])

    2014-01-02 00:00:00

    0 讨论(0)
  • 2020-12-24 10:08
    import pandas_datareader.data as web
    import datetime
    start = datetime.datetime(2015, 1, 1)
    end = datetime.datetime(2016, 1, 1)
    web.DataReader('GOOGL', 'yahoo', start, end)
    
    0 讨论(0)
  • 2020-12-24 10:13

    This should do it.

    import pandas as pd
    from pandas.io.data import DataReader
    
    symbols_list = ['ORCL', 'TSLA', 'IBM','YELP', 'MSFT']
    d = {}
    for ticker in symbols_list:
        d[ticker] = DataReader(ticker, "yahoo", '2014-12-01')
    pan = pd.Panel(d)
    df1 = pan.minor_xs('Adj Close')
    print(df1)
    
    #df_percent_chg = df1.pct_change()
    
    0 讨论(0)
提交回复
热议问题