Skip to content

API: to_excel with merge_cells=False treats index and columns differently #60274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rhshadrach opened this issue Nov 10, 2024 · 3 comments · Fixed by #60293
Closed

API: to_excel with merge_cells=False treats index and columns differently #60274

rhshadrach opened this issue Nov 10, 2024 · 3 comments · Fixed by #60293
Labels
Bug IO Excel read_excel, to_excel MultiIndex
Milestone

Comments

@rhshadrach
Copy link
Member

rhshadrach commented Nov 10, 2024

df = pd.DataFrame({"a": [1, 1], "b": [2, 3], "c": 4, "d": 5}).set_index(["a", "b"])
df.columns = pd.MultiIndex.from_tuples([("x", "y"), ("x", "z")])
df.to_excel("test.xlsx", merge_cells=False)

image

In the above the multi-level nature of the index is maintained, however the columns are collapsed to a single row in the form x.y, x.z. It seems to me that these should be treated the same. The output should be multiple rows of non-merged cells.

@rhshadrach rhshadrach added IO Excel read_excel, to_excel MultiIndex Needs Discussion Requires discussion from core team before further action API - Consistency Internal Consistency of API/Behavior labels Nov 10, 2024
@rhshadrach
Copy link
Member Author

rhshadrach commented Nov 10, 2024

@WillAyd @mroeschke - any thoughts? The fix is trivial although I think it should undergo deprecation if we move forward, and it's not clear to me what the best approach is.

@WillAyd
Copy link
Member

WillAyd commented Nov 10, 2024

I think it's ok and maybe doesn't even need a deprecation (?)

@mroeschke
Copy link
Member

Yeah I would be OK to treat this as a "bug fix" especially for 3.0

@rhshadrach rhshadrach removed the Needs Discussion Requires discussion from core team before further action label Nov 11, 2024
@rhshadrach rhshadrach added Bug and removed API - Consistency Internal Consistency of API/Behavior labels Nov 12, 2024
@rhshadrach rhshadrach added this to the 3.0 milestone Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Excel read_excel, to_excel MultiIndex
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants