Add CSS to permanently display the index or column headers in a scrolling frame.
Whether to make the index or column headers sticky.
Required to configure the width of index cells or the height of column header cells when sticking a MultiIndex (or with a named Index). Defaults to 75 and 25 respectively.
If axis is a MultiIndex the specific levels to stick. If None will stick all levels.
Notes
This method uses the CSS ‘position: sticky;’ property to display. It is designed to work with visible axes, therefore both:
styler.set_sticky(axis=”index”).hide(axis=”index”)
styler.set_sticky(axis=”columns”).hide(axis=”columns”)
may produce strange behaviour due to CSS controls with missing elements.
Examples
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> df.style.set_sticky(axis="index")
Please see: Table Visualization for more examples.
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.io.formats.style.Styler.set_sticky.html