我正在将.csv文件读入数据帧(CorpActionsDf),但是当我打印CorpActionsDf的头部时,我发现我缺少第一行数据:
.cvs数据的头:
BBG.XAMS.ASML.S 24/04/2015 0.7 Annual Regular Cash
BBG.XAMS.ASML.S 25/04/2014 0.61 Annual Regular Cash
BBG.XAMS.ASML.S 26/04/2013 0.53 Annual Regular Cash
BBG.XAMS.ASML.S 26/11/2012 9.18 None Return of Capital
BBG.XAMS.ASML.S 27/04/2012 0.46 Annual Regular Cash
CorpActionsDf负责人:
date factor_value reference factor
unique_id
BBG.XAMS.ASML.S 25/04/2014 0.61 Annual Regular Cash
BBG.XAMS.ASML.S 26/04/2013 0.53 Annual Regular Cash
BBG.XAMS.ASML.S 26/11/2012 9.18 None Return of Capital
BBG.XAMS.ASML.S 27/04/2012 0.46 Annual Regular Cash
BBG.XAMS.ASML.S 26/04/2011 0.40 Annual Regular Cash
如您所见,csv中的第一行数据从数据帧中丢失.
BBG.XAMS.ASML.S 24/04/2015 0.7 Annual Regular Cash
我的代码如下:
def getCorpActionsData(rawStaticDataPath):
pattern = 'CorporateActions'+ '.csv'
staticPath = rawStaticDataPath
with open(staticPath+pattern,'rt') as f:
#staticDf=pd.read_csv(f,engine='c',header=0,index_col=0, parse_dates=True, infer_datetime_format=True,usecols=(0,3))
CorpActionsDf=pd.read_csv(f,engine='c',header=0,index_col=0, parse_dates=True, infer_datetime_format=True,names=['unique_id', 'date','factor_value','reference','factor'])
print('CorpActionsDf')
print(CorpActionsDf.head())
有人知道我想念什么吗?
谢谢
解决方法:
您是否尝试过header = None而不是header = 0?
Docu对header = 0表示:
“如果未传递任何名称,则默认行为就像设置为0,否则设置为None.显式传递header = 0以能够替换现有名称.”
CorpActionsDf=pd.read_csv(f,engine='c',header=None,index_col=0, parse_dates=True, infer_datetime_format=True,names=['unique_id', 'date','factor_value','reference','factor'])
标签:python-3-x,python