The other answer didn't work for me - IPython.OutputArea
doesn't seem to exist any more (as far as I can tell, at least not in VSCode and based on the IPython code).
I managed to make a DataFrame scrollable with a somewhat hacky solution of generating the HTML table for the DataFrame and then putting that into a div
, which can be made scrollable using CSS. In this case all we really need to do is set the height to some pixel value.
We can also set the overflow to auto
and the width to fit-content
so the scrollbar appears right next to the DataFrame, instead of all the way on the right of the window.
import pandas as pd
from IPython.display import display, HTML
df = pd.DataFrame([(i, i) for i in range (20)])
pd.set_option("display.max_rows", None)
# Puts the scrollbar next to the DataFrame
display(HTML("<div style='height: 200px; overflow: auto; width: fit-content'>" +
df.style.render() +
"</div>"))
# Puts the scrollbar on the right side of the window
display(HTML("<div style='height: 200px'>" + df.style.render() + "</div>"))
Demo:
