-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
BUG: Override mi-columns in to_csv if requested #18110
Conversation
lgtm! |
doc/source/whatsnew/v0.21.1.txt
Outdated
@@ -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`) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]]) |
There was a problem hiding this comment.
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.
@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. |
@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! |
@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
c9c39c5
to
ccd5098
Compare
All green, so merging. |
Previously, MultiIndex columns weren't being overwritten when header was passed in for to_csv. Closes pandas-devgh-5539
Previously, MultiIndex columns weren't being overwritten when header was passed in for to_csv. Closes pandas-devgh-5539
Previously, MultiIndex columns weren't being overwritten when header was passed in for to_csv. Closes pandas-devgh-5539 (cherry picked from commit e1f3a70)
Previously,
MultiIndex
columns weren't being overwritten whenheader
was passed in forto_csv
.Closes #5539 (almost four years to the day, wow...)