-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Comments
Can you provide a minimal example of your code and the expectation |
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) |
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:
|
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. |
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
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
The text was updated successfully, but these errors were encountered: