This quick tutorial shows how to enable and configure column sorting in Pandas DataFrames using iTables. For a complete introduction to iTables, see our Getting Started with iTables: Interactive DataFrames in Python guide.
The Problem
When exploring data in Jupyter notebooks, you often need to sort by different columns to spot patterns, outliers, or top performers. Writing .sort_values() repeatedly is tedious, and you lose your original DataFrame order each time. iTables provides instant click-to-sort functionality on any column without modifying your data.
The Solution
Enable column sorting by displaying your DataFrame with iTables.
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, ordering=True)
The ordering=True parameter is the default, but you can set ordering=False to disable sorting.
Column sorting works through simple clicks. Click any column header to sort ascending (A to Z, 0 to 9). Click again to sort descending (Z to A, 9 to 0). Click a third time to return to the original order. The sort happens instantly in the browser without re-executing Python code, and the original DataFrame remains unchanged.
Try clicking the “capital” column to see countries sorted alphabetically by capital city. Click again to reverse the order. Click “latitude” or “longitude” to sort by geographic coordinates. The table reorders instantly while your DataFrame stays untouched.
You can sort by any column in your DataFrame. Text columns sort alphabetically, numeric columns sort by value, and date columns sort chronologically. Multi-column sorting isn’t supported through clicks, but you can pre-sort your DataFrame with pandas before displaying it if you need data sorted by multiple criteria.
Disable Sorting When Needed
Turn off sorting for specific use cases.
show(df, ordering=False)
Column headers become non-clickable, preserving the current row order.
Disable sorting when working with time series data where chronological order matters, when displaying pre-sorted data that should remain in a specific order, or during presentations where you don’t want viewers changing the order. For financial data showing quarterly results or log files showing events in sequence, disabling sorting ensures the meaningful order is preserved.
Conclusion
Column sorting works automatically with iTables. Just click column headers to explore your data from different angles instantly without writing any sorting code. The feature enables quick data exploration while keeping your original DataFrame intact and ready for further analysis.
