multiindex column in to_excel
See original GitHub issuelink to #1651
Saving a multiindex column to_excel saves a sparse index.
Migrated from this StackOverflow question, with a smaller DataFrame.
In [1]: m = MultiIndex.from_tuples([(1,1),(1,2)], names=['a','b'])
In [2]: df = DataFrame([[1,2],[3,4]], columns=m)
In [3]: df
Out[3]:
a 1
b 1 2
0 1 2
1 3 4
In [4]: df.to_excel('test.xls')
Saves the xls:
1.1 .2
0 1 2
1 3 4
This differs from how to_csv
(which is not sparse):
,"(1L, 1L)","(1L, 2L)"
0,1,2
1,3,4
Issue Analytics
- State:
- Created 11 years ago
- Comments:18 (5 by maintainers)
Top Results From Across the Web
reading excel sheet as multiindex dataframe through pd ...
Having created the structure of the multiindex columns, I'm unable to fit this template to the dataframe; how to do this? Related. 7...
Read more >pandas.read_excel — pandas 0.20.2 documentation
Row (0-indexed) to use for the column labels of the parsed DataFrame. If a list of integers is passed those row positions will...
Read more >Export to excel for multiindex columns · Issue #11292 - GitHub
Hi All, I'm just using 0.17 for testing exporting multiindex column dataframe. When i'm pivot table dataframe with X column as index (and ......
Read more >Add an index column (Power Query) - Microsoft Support
Create an index column to show the number of a row in a query. This is especially useful when you are filtering by...
Read more >10.5 Excel files — Pandas Doc - GitHub Pages
read_excel can read a MultiIndex index, by passing a list of columns to index_col and a MultiIndex column by passing a list of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jreback Can this be reopened? I also get this problem.
I’ve commented this on #6618, which seems related. From what I can see, the problem is that pandas is reserving the first column of the header rows to the MultiIndex, and creates a new line for the row index name even if it is unnamed:
This bug was fixed some time ago for simple columns, but it was probably not a very good solution, since it is still buggy for MultiIndex columns:
Version information:
@mappingvermont I’m getting the same result with a real example. I think it is a bug. Using latest version pandas 0.19.2