There are certain functions in Python that perform unique functions, which many Python programmers may not know about. They may not be absolutely crucial to know, but they can perform some useful functions.
In this article, we will briefly discuss two such functions: tabulate, and tqdm.
create tables with tabulate
The tabulate function, which is in the tabulate library, can be used to create nicely-formatted tables in Python.
We first install the tabulate library:
pip install tabulate
Then import the tabulate function in our code:
from tabulate import tabulate
The tabulate function can transform many different things into easy to read plain-text tables, such as a list of lists, dictionary of iterables, and others.
For example, if we have the following list of lists:
table = [['First Name', 'Last Name', 'Age'], ['John', 'Smith', 39], ['Mary', 'Jane', 25], ['Jennifer', 'Doe', 28]]
We can turn it into into a much more readable plain-text table using the tabulate function:
print(tabulate(table))

Since the first list in the list of lists contains the names of columns as its elements, we can set it as the column or header names by passing ‘firstrow’ as the argument for the headers parameter:
print(tabulate(table, headers='firstrow'))

The tabulate function also contains a tablefmt parameter, which allows us to improve the appearance of our table using pseudo-graphics:
print(tabulate(table, headers='firstrow', tablefmt='fancy_grid'))

We can create the same table above using the following dictionary of iterables:
info = {'First Name': ['John', 'Mary', 'Jennifer'], 'Last Name': ['Smith', 'Jane', 'Doe'], 'Age': [39, 25
print(tabulate(info, headers='keys', tablefmt='fancy_grid'))

If we have missing values in the table, we can fill them with whatever we choose by passing in an argument for the missingval parameter.
For a more comprehensive overview of the tabulate function:
display progress bars using tqdm
The tqdm function, from the tqdm library, allows us to display smart progress bars in Python.
We first install tqdm:
pip install tqdm
We then import the tqdm function in our code:
from tqdm import tqdm
To use the tqdm function to show a progress bar for our Python loops, we just wrap any iterable with tqdm(iterable).
Let’s look at an example in Jupyter Notebook:

We wrapped the iterable, which in this example is the range object, with the tqdm function. The progress bar can be seen below the Jupyter Notebook cell. As the for loop is running, it shows the {elapsed time}<{remaining} time, and iterations per second.
We can also use tqdm to show progress bars with functions that iterate through an iterable, such as the map, filter, and reduce functions.
If you are working in Jupyter Notebook, you can instead import the tqdm function from the tqdm.notebook submodule, which provides a more visually appealing progress bar that includes some color hints (blue for normal, green for completed, red for error/interrupt, light blue for no ETA):
from tqdm.notebook import tqdmdef
add(num):
return reduce(lambda x,y: x+y, tqdm(range(num+1))) if type(num) == int else 0

If you enjoy reading stories like these and want to support me as a writer, consider signing up to become a Medium member. It’s $5 a month, giving you unlimited access to stories on Medium. If you sign up using my link, I’ll earn a small commission.
I hope you enjoyed this short tutorial on the tabulate and tqdm functions. Thank you for reading!