BUG: read_excel with multi-indexed column ignores index_col=None
See original GitHub issueFrom SO: http://stackoverflow.com/questions/34020061/excel-to-pandas-dataframe-using-first-column-as-index
@chris-b1 another one on the multi-index excel issues … 😃
Small test case: content of excel file:
A | A | B | B |
---|---|---|---|
key | val | key | val |
1 | 2 | 3 | 4 |
1 | 2 | 3 | 4 |
gives:
In [2]: pd.read_excel("test_excel_index_col.xlsx", header=[0,1], index_col=None)
Out[2]:
A A B
key val key val
1 2 3 4
1 2 3 4
It’s not super clear in the formatting of the dataframe, but the [1, 1] is the index and [A, key] are seen as the level names of the multi-indexed columns.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:5
- Comments:18 (9 by maintainers)
Top Results From Across the Web
Reading partially multi-indexed Excel files in Python
What I am looking for is to read it using python while maintaining the multi-indexes on the columns. Currently, I use the following...
Read more >pandas.DataFrame.to_excel — pandas 1.5.2 documentation
Column label for index column(s) if desired. ... Write MultiIndex and Hierarchical Rows as merged cells. ... Read an Excel file into a...
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 >unable to write multi-index dataframe to excel-Pandas,Python
After searching the web, I used pywin32 to solve the problem. import win32com.client as win32 df.to_excel('data.xlsx', index = True) excel = win32.gencache.
Read more >Pandas to_excel: Writing DataFrames to Excel Files
How to save a Pandas DataFrame to Excel; How to customize the sheet name of your DataFrame in Excel; How to customize the...
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
Vote for index_col=False to fix this
As of now I still see the same issue. when using multi headers with read_excel, pandas always assigns the first column as index.