How to display the progress bar (tqdm)

Basic information

tqdm makes it easy to display a progress bar to check the progress of time-consuming processes such as for statements.

Requires installation

$ pip install tqdm

How to use

To use it, just enclose the iterable object in tqdm.

tqdm_test.py


from tqdm import tqdm

df = pd.read_csv("data.csv", encoding="UTF-8")

#Consider a scene where pandas data is processed for statement
#To use tqdm, just enclose it in tqdm
for row, item in tqdm(df.iterrows()):
    print(item)

memorandum

How to manually set the progress bar value

Until now, I have only used the above method. However, for some reason, the upper limit of the progress bar became "?", So I found out how to set the maximum number manually, so I will write it as a memorandum for myself.

tqdm_test.py


from tqdm import tqdm

df = pd.read_csv("data.csv", encoding="UTF-8")

#How to manually update the progress bar at the end of the for statement by enclosing it in the with statement
#total=Set the upper limit with. This time, I chose the number of df. The increase is.pbar.Specify with update.
with tqdm(total=len(df)) as pbar:
    for row, item in tqdm(dataframe.iterrows()):
        print(item)
        pbar.update(1)

In the case of jupyter notebook

With from tqdm.notebook, it became an easy-to-read progress bar.

tqdm_test.py


from tqdm.notebook import tqdm

Recommended Posts

How to display the progress bar (tqdm)
I want to display the progress bar
[Python] Progress display by progress bar using tqdm
[Python] How to change the date format (display format)
I want to display the progress in Python!
How to use the generator
How to use the decorator
How to view progress bar on Jupyter Notebook to see progress
How to increase the axis
How to start the program
What to do if the progress bar is not displayed in tqdm of python
How to temporarily implement a progress bar in a scripting language
How to calculate the autocorrelation coefficient
How to use the zip function
[Rails] How to display Google Map
How to use the optparse module
How to read the SNLI dataset
How to get the Python version
[Python] How to import the library
How to overwrite the output to the console
How to use the ConfigParser module
Real-time display of server-side processing progress in the browser (implementation of progress bar)
[Memo] How to use BeautifulSoup4 (2) Display the article headline with Requests
[Memo] How to use BeautifulSoup4 (3) Display the article headline with class_
How to display bytes in the same way in Java and Python
How to suppress display error in matplotlib
How to use the Spark ML pipeline
[Memo] How to use BeautifulSoup4 (1) Display html
[Python] How to display random numbers (random module)
How to check the version of Django
How to solve the bin packing problem
How to set the server time to Japanese time
How to manually update the AMP cache
[Linux] How to use the echo command
How to use the Linux grep command
How to display multiplication table in python
How to display emoji on Manjaro Linux
How to display python Japanese with lolipop
How to get colored output to the console
How to operate Linux from the console
How to access the Datastore from the outside
How to use the IPython debugger (ipdb)
[Python] A progress bar on the terminal
How to display Hello world in python
[Python] How to specify the window display position and size of matplotlib
Trial to judge the timing of the progress display of the for loop using 0b1111 ~
Mouse over Matplotlib to display the corresponding image
How to assign multiple values to the Matplotlib colorbar
How to display Map using Google Map API (Android)
How to calculate the volatility of a brand
Display the edge
[python] How to display list elements side by side
How to use the C library in Python
How to specify the launch browser for JupyterLab 3.0.0
How to find the area of the Voronoi diagram
How to use MkDocs for the first time
How to specify the NIC to scan with amazon-dash
How to turn off the scale value display while leaving the grid with matplotlib
How to try the friends-of-friends algorithm with pyfof
How to use the graph drawing library Bokeh
How to print debug messages to the Django console