-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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: to_excel swaps order of values of duplicate columns #11007
Comments
@jorisvandenbossche I got this bug when running your new example
Do you know what went wrong? |
as @jreback said, you have to look at the openpyxl version |
Still got this error after upgrade. (I was actually using the most updated one earlier)
|
yeh, that version is borked :) |
latest conda version is ok, its the pip version that is a problem (which we are not testing with .... :<) |
Okay. I'll try conda then. |
There have been some duplicate-column fixes previously: #5237, but clearly not solved all. cc @neirbowj |
Another report of this on SO: http://stackoverflow.com/questions/32592526/potential-bug-in-pandas-xlsxwriter-pd-to-excel-not-working-well |
I think the code causing the issue the following (and was introduced by me): # Get a frame that will account for any duplicates in the column names.
col_mapped_frame = self.df.loc[:, self.columns]
# Write the body of the frame data series by series.
for colidx in range(len(self.columns)):
series = col_mapped_frame.iloc[:, colidx]
for i, val in enumerate(series):
yield ExcelCell(self.rowcounter + i, colidx + coloffset, val) If so then the Any suggestions on a better way to fix this? |
So the problem is of course that the
So a possible solution I think, is to only use @jmcnamara do you have time to try to push a fix? Would be nice if we could still put this in 0.17 as this is quite a serious bug |
@jorisvandenbossche I can work on a fix at the weekend. |
On master, as a small example:
gives:
So the values of columns 2 and 3 are swapped (not the column names)
BTW, this happens both with .xlsx as .xls (openpyxl / xlsxwriter / xlwt)
Possibly related: #10982, #10970
The text was updated successfully, but these errors were encountered: