Introduction
Python is a popular programming language designed for general-purpose programming. It was developed, focusing mainly on code readability. It allows programmers to convey their idea in fewer lines of code. You can use Python for various basic purposes such as software development, web development, performing mathematical calculations, and shell scripting.

In this blog, we will learn how to produce progress bars using the tqdm library in Python. We will also discuss in brief about tqdm library and its applications.
tqdm - Progress Bars for Python
The word ‘tqdm’ comes from the Arabic word ‘Taqadum’, which means progress. Whenever you are executing any task, it feels good to see little progress. If you have a simple progress bar in your code or script to tell your progress or give you proper feedback, it eases your mind. This way, your hours of hard work won’t go in vain.

Introduction to tqdm library
The tqdm is a Python library that creates a small progress bar for the Python loops. You only have to wrap tqdm with any iterable to execute. These progress bars can be used for data processing, downloading, machine learning models, etc. It not only shows you how much time has passed but also shows you the estimated time remaining for the completion.
Also see, Divmod in Python, Swapcase in Python
Important Parameters
Look into the table below for the several parameters offered along with the tqdm library.
Parameter |
Description |
Syntax |
| desc | It specifies the description of your progress bar. | tqdm (self, iterable, desc= “Text You want”) |
| total | It mentions the total number of expected iterations. | tqdm (self, iterable, total= 500) |
| disable | It is used to disable the progress bar completely. | tqdm (self, iterable, disable= true) |
| ncols | It frames the entire width of the output message. It is dynamic to the window’s size. | tqdm (self, iterable, ncols= 100) |
| mininterval | You can change the minimum progress display using this parameter. The default is set to 0.1 seconds. | tqdm (self, iterable, mininterval= 3) |
| ascii | Using this parameter, you can use the ASCII characters to fill the progress bar. | tqdm (self, iterable, ascii= “123456789$”) |
| unit | The unit of time can be changed using this parameter. The default is set to “it”. | tqdm (self, iterable, unit= “ticks”) |
| intial | Using this parameter, you can change the initial value of the progress bar | tqdm (self, iterable, initial= 5) |
Hands-on implementation with tqdm
Now you are well versed with the several aspects of the tqdm library, we will move to the implementation part.
Installation
The tqdm library is a part of the Python Package Index (PyPI). You can use the syntax below to install the library.
pip install tqdm
Importing Libraries
To import the tqdm library, start with the following line of code.
from tqdm import tqdm
Importing Notebooks
Suppose you want to export any notebooks such as IPython or Jupyter. In that case, you can import it while working with the tqdm library. You can use the syntax below for the same.
from tqdm.notebook import tqdm, trange
Using the tqdm library with for loop
You can use the syntax to look into the syntax of using the tqdm library with for loop.
for i in tqdm(range(1000)):
pass
Multiple Progress Bars
Use the Python code below to create Multiple Progress Bars.
from tqdm.notebook import tqdm
for i in range(20, desc= ‘test’):
sleep(0.01)
for x in range(1000, desc= ‘t’):
sleep(0.01)
Applications of tqdm
There can be various applications of the tqdm library. Some prominent ones are discussed further.
Data Science
Use the steps below to understand the concept better. Here, we will be using an example of a Hotel Booking dataset. We will integrate tqdm into the pandas dataframe and use progress_apply to apply functions to the dataframe with the progress bar.
1. We will load the dataset and display the top 5 rows using the following Python code.
import pandas as p
d = p.read_csv("bookings.csv")
df.head(5)
2. Create a new column name using the customer’s name.
3. Use the following code to generate progress bars for the pandas dataframe, add a bar with the label Processing the column, lower the string, replace space with ‘-’, and display the top two rows.
tqdm.pandas(desc="Processing the column")
def name(text):
return text.lower().replace(" ","-")
df['name'] = df['name'].progress_apply(name)
df.head(2)
Parallel Processing Utility
The tqdm library offers a utility tqdm.contrib.concurrent for parallel processing. Use the code below to extract email_provider from the email column. It will display the top five columns of the email_provider column.
from tqdm.contrib.concurrent import map
def extraction(email):
return email.split("@")[1].split(".")[0]
df["provider"] = map(
extraction,
df["email"],
workers=10,
size=128,
desc="Extracting provider",
colour='green'
)
df["provider"].head().to_frame()
Read about Bitwise Operators in C here.
Practice this code with the help of Online Python Compiler



