Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Pandas exporting to Excel (xls, xlsx) with multilevel columns #11408
I want collect few tables into the one with pandas. I use the code presented below:
import pandas as pd import itertools import types df = None for frame in ['x', 'y']: df_ = pd.read_excel(u'%s.xlsx' % frame) df_ = df_.set_index([u'time']) parameters = list(df_.columns) tuples =  for tup in itertools.product([frame,], parameters): tuples.append(tup) columns = pd.MultiIndex.from_tuples(tuples, names=[u'Frames',u'Parameters']) df_new = pd.DataFrame(columns=columns, index=df_.index) for par in parameters: df_new[frame, par] = df_[par] del df_ if df is None: df = df_new else: df = pd.concat([df, df_new], axis=1) df.to_excel('merged_xlsx.xlsx') df.to_excel('merged_xls.xls')
Is it bug in XLSX pandas engine (openpyxl)? Or what is wrong in my code?
P.S. This issue is copy of my question on stackoverflow. It was suggested as bug and was adviced to post here.
@dinya Thanks for the report!
It is always easier if you provide an easier reproducible example (as we cannot run your code above), but I made a small one:
Can you see if this reproduces your issue?
I can't reproduce it with 0.17.0, but I was using openpyxl 1.6.1
I just tested this with Python 3.4.3, pandas 0.17.0, xlsxwriter 0.7.3, and openpyxl 1.8.5 and cannot replicate. I tested with Python 3.4.3, a dev copy of pandas, xlsxwriter 0.7.6, and openpyxl 2.0.2 and cannot replicate. I tested with Python 2.7.10, a dev copy of pandas, xlsxwriter 0.7.6, and openpyxl 1.6.2, and cannot replicate.
However, I tested with Python 2.7.10, a dev copy of pandas, xlsxwriter 0.7.6, and openpyxl 2.3, and I do replicate.
I wonder it this relates to my pull request and different behaviors based on python/openpyxl combinations detailed here (scroll to the bottom): #11328
@chris-b1 would like your opinion