Skip to content

BUG: Override mi-columns in to_csv if requested #18110

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

Merged
merged 1 commit into from
Nov 5, 2017

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Nov 4, 2017

Previously, MultiIndex columns weren't being overwritten when header was passed in for to_csv.

Closes #5539 (almost four years to the day, wow...)

@gfyoung gfyoung added Bug MultiIndex Output-Formatting __repr__ of pandas objects, to_string labels Nov 4, 2017
@gfyoung gfyoung added this to the 0.21.1 milestone Nov 4, 2017
@jreback
Copy link
Contributor

jreback commented Nov 4, 2017

lgtm!

@@ -77,6 +77,7 @@ I/O

- Bug in class:`~pandas.io.stata.StataReader` not converting date/time columns with display formatting addressed (:issue:`17990`). Previously columns with display formatting were normally left as ordinal numbers and not converted to datetime objects.
- Bug in :func:`read_csv` when reading a compressed UTF-16 encoded file (:issue:`18071`)
- Bug in ``DataFrame.to_csv(...)`` when the table had ``MultiIndex`` columns, and a list of strings was passed in for ``header`` (:issue:`5539`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly necessary, but might be nice to do :meth:`DataFrame.to_csv` to provide a link.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gfyoung can you update this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there was actually only one place (mine) which needed this fix.

# see gh-5539
columns = pd.MultiIndex.from_tuples([("a", 1), ("a", 2),
("b", 1), ("b", 2)])
df = pd.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like DataFrame and MultiIndex are already imported, so could remove the pd., if you feel that's cleaner/worth an edit.

@gfyoung
Copy link
Member Author

gfyoung commented Nov 4, 2017

@jschendel : Thanks for the comments. I'm going to hold off from making the changes here because I see that your comments are applicable to several other points in those two files. Will make another PR to clean those up once this one is merged.

@jschendel
Copy link
Member

@gfyoung : Sounds good, was actually thinking of doing something similar myself. I'm usually hesitant to bring up points like that when I see them unless there's already edits that need to be made, since they're not super critical and don't want people to feel like I'm nagging them!

@jreback
Copy link
Contributor

jreback commented Nov 4, 2017

@gfyoung tiny comment. after that, merge when ready.

Previously, MultiIndex columns weren't being
overwritten when header was passed in for to_csv.

Closes pandas-devgh-5539
@gfyoung gfyoung force-pushed the header-override-to-csv branch from c9c39c5 to ccd5098 Compare November 4, 2017 22:49
@gfyoung gfyoung merged commit e1f3a70 into pandas-dev:master Nov 5, 2017
@gfyoung
Copy link
Member Author

gfyoung commented Nov 5, 2017

All green, so merging.

@gfyoung gfyoung deleted the header-override-to-csv branch November 5, 2017 04:37
1kastner pushed a commit to 1kastner/pandas that referenced this pull request Nov 5, 2017
Previously, MultiIndex columns weren't being
overwritten when header was passed in for to_csv.

Closes pandas-devgh-5539
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Previously, MultiIndex columns weren't being
overwritten when header was passed in for to_csv.

Closes pandas-devgh-5539
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request Dec 8, 2017
Previously, MultiIndex columns weren't being
overwritten when header was passed in for to_csv.

Closes pandas-devgh-5539

(cherry picked from commit e1f3a70)
TomAugspurger pushed a commit that referenced this pull request Dec 11, 2017
Previously, MultiIndex columns weren't being
overwritten when header was passed in for to_csv.

Closes gh-5539

(cherry picked from commit e1f3a70)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug MultiIndex Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants