'Pandas DataFrame Table Vertical Scrollbars
I have a large (vertically) pandas dataframe that I would like to display as a nice table with scrollbars. I can get it to display the table with all the rows but I cannot get the scrollbars to display.
def data(x):
strData = strData[['Data1','Data2','Data3']]
display(strData)
output: No vertical scrollbars
Solution 1:[1]
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:
Solution 2:[2]
Just pass the dataframe and observe the magic.
def table(df):
import plotly.graph_objs as go
fig = go.Figure(data=[go.Table(
header=dict(values=list(df.columns),
align='left'),
cells=dict(values=[df[i] for i in df.columns],
align='left'))
])
return fig
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | ASAD ASHRAF KAREL |


