Q: How to display large matrix in pandas with scroll bars in Jupyter Notebook? I have written about 100 lines of code in a Jupyter Notebook cell, and in the middle of the code, I have something like this:
pd.set_option('display.max_rows', 1000)
x = np.random.rand(1000,3)
display(pd.DataFrame(x))

It shows me the entire table, but I was wondering if there is an option in Pandas to limit the vertical size of the output table & add a vertical scroll bar to allow better viewing. I mean, a separate vertical scroll bar than the cell output scroll bar (which I have toggled off by the way).
From what I understand, one option is to use Plotly table visualization as explained in this, but I wanted to avoid that if possible & use a more native solution because with plotly / Dash, the table text is not selectable anymore (Not sure haven't tested it yet though).

A: Found the solution from Pandas DataFrame Table Vertical Scrollbars. Add this:
from IPython.display import display, HTML

# Puts the scrollbar next to the DataFrame
display(
    HTML(
        "<div style='height: 200px; overflow: auto; width: fit-content'>" +
        df1.to_html() +
        "</div>"
    )
)


This answer was posted as an edit to the question How to display large matrix in pandas with scroll bars in Jupyter Notebook? by the OP dani under CC BY-SA 4.0.

A: I created this function that I always copy paste on any of my notebook
def print_df(df, head=10):
    with pd.option_context('display.max_rows', None, 'display.max_columns', None):
        display(df.head(head))

and I just need to call print_df(df) to check some sample data
