pythonpandascsvpanelzipline

Convert a csv to panel pandas for zipline


I'm trying to convert a csv to a panel in pandas as follow, but jupyter keep alert "ValueError: Panel constructor not properly called!", although I've done as the guide in https://blog.quantinsti.com/importing-csv-data-zipline-backtesting/:

My csv file have structure:

data = pd.read_csv('.../MWG.csv', index_col=0, parse_dates=['Date'])
data.fillna(method='ffill')

     Date       Open        High        Low         Close       Volume
Symbol                      
MWG 2019-12-12  113.0000    113.5000    112.7000    113.4000    366190
MWG 2019-12-11  110.5000    113.0000    110.3000    113.0000    314710
MWG 2019-12-10  110.9000    111.4000    110.0000    111.0000    412000
MWG 2019-12-09  110.8000    111.6000    110.0000    110.9000    526010
MWG 2019-12-06  110.6000    111.0000    110.0000    110.8000    468980
MWG 2019-12-05  113.2000    113.5000    110.6000    110.6000    544700
MWG 2019-12-04  109.0000    113.0000    108.6000    113.0000    574630

My code is:

panel = pd.Panel(data)
panel.minor_axis = ['Open', 'High', 'Low', 'Close', 'Volume']
panel.major_axis = panel.major_axis.tz_localize(pytz.utc)

And the alerts as:

ValueError: Panel constructor not properly called!

Please help me to correct the issue, so I could have input for Zipline to run strategy.


Solution

  • You can use the panel for ndarray or dict of dataframes. You can try this,

    >>> data = {}
    >>> data['MGW'] = pd.read_csv('.../MWG.csv', index_col=0, parse_dates=['Date'])
    >>> panel = pd.Panel(data)