I have code as following:
import pandas as pd
import numpy as np
import datetime
from datetime import datetime
from datetime import timedelta
import pytz
start_date = '2015-01-01'
end_date = '2017-09-15'
def data_symbol():
dates=pd.date_range(start_date,end_date)
df=pd.DataFrame(index=dates)
df_temp=pd.read_csv('/home/furqan/Desktop/python_data/AVN.csv',usecols=['Date','Open', 'High', 'Low', 'Close', 'Volume'],
parse_dates=True,index_col='Date',na_values=['nan'])
#df_temp = df_temp.rename(columns={'Close': 'price'})
df=df.join(df_temp)
df=df.fillna(method='ffill')
df=df.fillna(method='bfill')
df.index.names = ['Date']
return df
data = data_symbol()
print(data)
panel = pd.Panel(data)
panel.minor_axis = ['Open', 'High', 'Low', 'Close', 'Volume']
panel.major_axis = panel.major_axis.tz_localize(pytz.utc)
After printing data it results in an error as follows: "Panel constructor not properly called!" The data is as follows:
Open High Low Close Volume
Date
2015-01-01 33.85 35.30 33.40 35.07 1222500.0
2015-01-02 35.07 36.82 35.00 36.32 1252000.0
2015-01-03 35.07 36.82 35.00 36.32 1252000.0
2015-01-04 35.07 36.82 35.00 36.32 1252000.0
2015-01-05 36.32 36.30 35.31 35.76 629500.0
2015-01-06 35.76 35.92 34.75 34.87 585000.0
2015-01-07 34.87 35.85 34.90 35.23 341000.0
2015-01-08 35.23 35.50 34.76 34.92 253500.0
2015-01-09 34.92 35.50 34.60 34.73 310500.0
The purpose to convert it into panel data so that I can use the local data file in Zipline.
I just faced this problem recently and fixed it by changing this line:
into
change 'abc' into whatever name you like