Sticky header and index for large data frames in Jupyter · Issue #29072 · pandas-dev/pandas (original) (raw)

Problem description

When displaying a large data frame in Jupyter the number of columns will be limited by max_cols set in the default setting, and all the rows will be displayed.

I would like to add an option in the default settings so that large data frames will be displayed with a sticky header and index and then be able to scroll though the data frame.

Proof of concept solution

Following the solution for html tables found at Stackoverflow: Table with fixed header and fixed column on pure css with the solution shown in action here HTML and CSS Solution
I came up with the following solution (which follows the same way of <style scoped> as the _repr_html_ method):

import numpy as np import pandas as pd from IPython.display import HTML

Dummy dataframe

columns = [chr(i) for i in range(ord('a'),ord('z')+1)] data = np.random.rand(len(columns),len(columns)) df = pd.DataFrame(data, columns=columns)

Solution

Getting default html as string

df_html = df.to_html()

CSS styling

style = """

"""

Concatenating to single string

df_html = style+'

'+df_html+"\n
"

Displaying df with sticky header and index

HTML(df_html)


I would therefore like to know if others also would like to have this feature in pandas?
Otherwise I guess I would make it to an independent module that wraps the _repr_html_ method.
I know that it is not just a matter of adding the new styling above for the general case, but the above solution is a minimal working solution.
A related issues is #28091