Skip to content

BUG: Styler.set_sticky(axis="columns") does not work properly with Multi-Index Rows #42537

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

Closed
2 of 3 tasks
UncleHoo opened this issue Jul 14, 2021 · 5 comments · Fixed by #42799
Closed
2 of 3 tasks

BUG: Styler.set_sticky(axis="columns") does not work properly with Multi-Index Rows #42537

UncleHoo opened this issue Jul 14, 2021 · 5 comments · Fixed by #42799
Labels
Bug Styler conditional formatting using DataFrame.style
Milestone

Comments

@UncleHoo
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

df.style.set_sticky(axis="columns")

Problem description

When "sticking" columns in a DataFrame as shown above it does not work correctly if the DataFrame has an Multi-index. If the DataFrame has only a single index field then it works correctly. When a Multi-Index or hierarchical index is used, the index columns stick, but the other column headers disappear.

Expected Output

That all columns headings, both for index and non-index columns should be visible when scrolling down the DataFame.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f00ed8f
python : 3.9.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19043
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Canada.1252

pandas : 1.3.0
numpy : 1.21.0
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 49.6.0.post20210108
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.22.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@UncleHoo UncleHoo added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 14, 2021
@attack68
Copy link
Contributor

Can you provide a minimal example of your code and the expectation

@attack68 attack68 added the Styler conditional formatting using DataFrame.style label Jul 14, 2021
@UncleHoo
Copy link
Author

If you run the code below you will get a sample DataFrame that when you scroll the headings disappear (normal behavior).

import pandas as pd
import numpy as np
pd.set_option('display.max_rows', None)
df = pd.DataFrame( { 
    "farm" : np.random.choice(["Grey Farm", "Blue Farm", 'Red Farm', "Green Farm"],100) ,
    "fruit" : np.random.choice(["Apples","Organes","Bananas","Blueberries"], 100) ,
    "January" : np.random.randint(1,100,100),
    "February" : np.random.randint(1,100,100),
    "March" : np.random.randint(1,100,100),
    "April" : np.random.randint(1,100,100),
    "May" : np.random.randint(1,100,100)
    } )
df

If you then run the following code you will get what you expect, which is the column headings staying at the top of the display as you scroll through the table. Again, what is expected:

df.style.set_sticky(axis=1)

Now if you create a multi-index on the DataFrame and then try to display it again, you will notice that the index columns remain visible, but the column headings themselves disappear from view.

df.set_index(["farm","fruit"],inplace=True)
df.style.set_sticky(axis=1)

@attack68
Copy link
Contributor

attack68 commented Jul 20, 2021

Ah I see this is not to do with MultiIndexs it is actually becuase the index has a Name and that creates a row which overwrites the column headers row (both are pinned at the top).

This needs two fixes:

@UncleHoo
Copy link
Author

Okay...............I assume then that you don't need anymore information from me for this bug?

@attack68
Copy link
Contributor

Okay...............I assume then that you don't need anymore information from me for this bug?

no, your example was enough, the PR i submitted will, in fact, correct this issue, but there are further items to deal with.

@attack68 attack68 removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jul 20, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3.2 milestone Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants