【发布时间】:2020-04-03 04:35:11
【问题描述】:
我想写一个多索引数据框到excel:
col = [['info', '', 'key'], ['alert', 'date', 'price'], ['alert', 'date', 'amount']]
df = pd.DataFrame(columns = pd.MultiIndex.from_tuples(col))
df.loc[0, :] = np.random.random(3)
df.to_excel('data.xlsx', index = False)
但是,出现错误:
NotImplementedError: Writing to Excel with MultiIndex columns and no index ('index'=False) is not yet implemented.
我检查了 pandas 版本:pd.__version__,结果是'0.25.3'。
如何解决问题?
谢谢。
【问题讨论】:
-
直接导出为 xlsx 对您来说有多重要?如果不是很重要,可以先导出为 CSV,然后加载到 Excel 中。
-
你能给我看看代码吗?
-
据说stackoverflow.com/questions/33633858/…中的0.17.0版本已经解决了这个问题。但是为什么我会遇到这个问题呢?
标签: pandas