question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: read_excel with multi-indexed column ignores index_col=None

See original GitHub issue

From 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:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
the-rccgcommented, Jul 10, 2018

Vote for index_col=False to fix this

2reactions
araespahancommented, Dec 15, 2017

As of now I still see the same issue. when using multi headers with read_excel, pandas always assigns the first column as index.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found