Skip to content

Wish: MultiIndex support #129

Description

@buhtz

Because of #62 I am aware that StyleFrame currently not support pandas.MultiIndex .
Would be great to have this in the future because multi indexes are a part of formatting a table.

Here is a small example illustrating the current behaviour:

#!/usr/bin/env python3
import os
import sys
import pathlib
import pandas
import styleframe
import styleframe.utils

print(styleframe._versions_)

df = pandas.DataFrame(
    data={
        'idx1': list('AABB'),
        'idx2': list('xyxy'),
        'X': [1234, 345, 33123, 2],
        'Y': [2.4133, 42.3, 3, 13.344]
        }
    )
df = df.set_index(['idx1', 'idx2'])
print(df)

file_path = pathlib.Path.cwd() / 'test.xlsx'

default_style = styleframe.Styler(
    font_size=14, font=styleframe.utils.fonts.aharoni)
sf = styleframe.StyleFrame(df, styler_obj=default_style)

sf.to_excel(file_path, index=True).save()
os.system(str(file_path))

The console output:

Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)]
pandas 1.3.0
openpyxl 3.0.9
StyleFrame 4.1
               X        Y
idx1 idx2
A    x      1234   2.4133
     y       345  42.3000
B    x     33123   3.0000
     y         2  13.3440

The Excel result:
image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions