How to Control Pagination in Large Pandas DataFrames with iTables

This quick tutorial shows how to control pagination in pandas DataFrames using iTables. For a complete introduction to iTables, see our Getting Started with iTables: Interactive DataFrames in Python guide.

The Problem

Large DataFrames in Jupyter notebooks are difficult to browse. By default, pandas displays only the first and last few rows, with the middle rows truncated. Scrolling through thousands of rows is impractical and slow. Pagination splits your data into manageable pages with clear navigation controls, making exploration easier and keeping your notebook responsive.

The Solution

Set custom page-length and menu options for your DataFrame.

 
from itables import init_notebook_mode, show
from itables.sample_dfs import get_countries

init_notebook_mode(all_interactive=True)
df = get_countries(html=False)
show(df, pageLength=25, lengthMenu=[10, 25, 50, 100])

The pageLength=25 parameter shows 25 rows per page by default, and lengthMenu adds a dropdown for users to choose a page size.

control pagination large pandas dataframes itables 

Navigation controls appear at the bottom of the table. Click “Previous,” “Next,” or page numbers to browse. The dropdown lets you instantly change how many rows appear per page. Page numbers adjust automatically based on total rows and page size, and you can jump directly to any page by clicking its number. A status bar displays “Showing 1 to 25 of 208 entries,” indicating your position in the dataset.

Try different settings based on your needs. Use pageLength=10 for presentations and narrow screens. Use pageLength=50 for detailed analysis when you have screen space. Set lengthMenu=[5, 10, 20, 50] for smaller datasets, or lengthMenu=[25, 50, 100, 200] for larger datasets.

Disable Pagination for Small DataFrames

Turn off pagination when all data fits on one screen.

 
small_df = df.head(20)
show(small_df, paging=False)

All rows display at once without navigation controls.

control pagination large pandas dataframes itables 

Use paging=True for DataFrames with many rows (e.g., 50 or more) where you want fast, responsive browsing. Use paging=False for small DataFrames (e.g., under 30 rows) when you want everything visible. Choose larger pageLength values for detailed analysis when you need more context; choose smaller values for presentations or when working with many columns on narrow screens.

For DataFrames with thousands of rows, pagination is essential. It renders only the current page, keeping your browser responsive. Without pagination, rendering 10,000 rows can significantly slow down your notebook.

Conclusion

Pagination is enabled by default in iTables. Customize pageLength and lengthMenu to match your dataset size and exploration needs for an optimal browsing experience.

Leave a Reply

Your email address will not be published. Required fields are marked *