Pandas read \u csv多索引列Spar

2024-04-20 03:53:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个CSV,标题如下

,Appreciation Return,,Income Return,,Total Return,,Cap Rate,,NCREIF Value Index,,10 Yr T-Bond,,
,Base,Aternative High Interest Rates,Base,Aternative High Interest Rates,Base,Aternative High Interest Rates,Base,Aternative High Interest Rates,Base,Aternative High Interest Rates,Base,Aternative High Interest Rates,

我试过标准调用:

df = pd.read_csv(f, header=[0,1], skiprows=3, skipinitialspace=True, tupleize_cols=True)

这不起作用,因为标题中有空的内容。这些数据最初是从Excel导出的,Excel将单元格连接起来。他们不再结合了。熊猫有没有可能把最后一个标题单元格带过去,因为它是以“稀疏”格式存储的

我希望有一个多重索引

Appreciation Return>Base; Appreciation Return>Aternative High Interest Rates

但相反,你会得到:

Appreciation Return>Base; NA>Aternative High Interest Rates

Tags: csvtrue标题basereturnrateexceltotal