Search code examples
pythonpandasyahoo-financedatareadermulti-index

Python / DataReader / Yahoo - with pandas' Panel deprecated, how can I instead bring stock data into multiindexed dataframes?


the pandas datareader tool which accesses the Yahoo Finance stock data seems to pull data directly into a panel - which I think believe will be dropped from pandas soon. Does anyone know how to pull data into a multiindexed dataframe in lieu of a panel?

import pandas_datareader as data
stock_data = data.DataReader(['AAPL','GE'], 'yahoo', datetime(2017,1,1), datetime.now())

In [121]: stock_data

Out [121]: 
    <class 'pandas.core.panel.Panel'>
    Dimensions: 6 (items) x 91 (major_axis) x 2 (minor_axis)
    Items axis: Open to Adj Close
    Major_axis axis: 2017-01-03 00:00:00 to 2017-05-12 00:00:00
    Minor_axis axis: AAPL to GE

Thanks so much!


Solution

  • I think you need Panel.to_frame:

    df = stock_data.to_frame()
    

    Also function Panel.transpose can be helpful if need swap MultiIndexes in indexes and columns.