我有如下代码:
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)
打印数据后会导致如下错误:“面板构造函数未正确调用!” 数据如下:
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
将其转换为面板数据的目的,以便我可以在 Zipline 中使用本地数据文件。