A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/11408 below:

Pandas exporting to Excel (xls, xlsx) with multilevel columns · Issue #11408 · pandas-dev/pandas · GitHub

Hello all,

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')

Source data is x.xlsx

and y.xlsx files.

XLS engine works well (merged_xls.xls):

But something is wrong (cells merging) with XLSX engine (merged_xlsx.xlsx):

Manual cells unmerging works in Excel:

Is it bug in XLSX pandas engine (openpyxl)? Or what is wrong in my code?

Versions: python-2.7.10, pandas-0.17.0, openpyxl-2.3.0.

P.S. This issue is copy of my question on stackoverflow. It was suggested as bug and was adviced to post here.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4