Member-only story
How to Easily Create Tables in Python
How to use the tabulate function to create nicely-formatted tables in Python
Being able to quickly organize our data into a more readable format, such as when data wrangling, can be extremely helpful in order to analyze the data and plan the next steps. Python offers the ability to easily turn certain tabular data types into nicely formatted plain-text tables, and that’s with the tabulate function.
install tabulate
We first install the tabulate library using pip install in the command line:
pip install tabulate
import tabulate function
We then import the tabulate function from the tabulate library in our code:
from tabulate import tabulate
And now we are ready to use the tabulate function!
tabular data types supported by tabulate
The tabulate function can transform any of the following into an easy to read plain-text table: (from the tabulate documentation)
- list of lists or another iterable of iterables
- list or another iterable of dicts (keys as columns)
- dict of iterables…