Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
BUG: to_excel swaps order of values of duplicate columns #11007
Comments
jreback
added the
IO Excel
label
Sep 5, 2015
jorisvandenbossche
added the
Bug
label
Sep 5, 2015
|
@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 |
jreback
added this to the
Next Major Release
milestone
Sep 8, 2015
|
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. |
jorisvandenbossche commentedSep 5, 2015
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