python-将多索引熊猫数据框导出到excel

问题描述:

我正在尝试从此GitHub问题中解决以下示例: https: //github.com/pandas-dev/pandas/issues/2701

I'm trying the following example from this (closed) GitHub issue: https://github.com/pandas-dev/pandas/issues/2701

import pandas as pd

m = pd.MultiIndex.from_tuples([(1,1),(1,2)], names=['a','b'])
df = pd.DataFrame([[1,2],[3,4]], columns=m)

df.to_excel('test.xls')

当我打开test.xls时,第3行上有一个空白行:

When I open test.xls, there is a blank line on row 3:

来自GitHub的示例图像没有以下空白行:

The example image from GitHub doesn't have this blank line:

这是一个错误吗?是否有可用于将多索引数据帧写入Excel的解决方法?我宁愿不走CSV路线,因为熊猫会为我完成合并和居中工作.

Is this a bug? And are there workaround available for writing multiindex dataframes to Excel? I'd rather not go the CSV route, as pandas will do the merge-and-center for me.

在Ubuntu 14.04和Windows 10上使用pandas版本0.19.2.

Using pandas version 0.19.2 on Ubuntu 14.04 and Windows 10.

我能够重现您所做的一切.这很可能是一个错误. 没有简单的方法,只能通过再次读取xlsx来删除该行.请将其添加到关闭的github链中,然后重新打开.

I am able to reproduce whatever you have done. This is most likely a bug. No easy way out of this but to delete that row by reading the xlsx in again. Please add this to the closed github chain and reopen it.