In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "What are the practical skills of progress bar in Python", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "What are the practical skills of the progress bar in Python"!
1 Introduction
tqdm, a progress bar library that is already very popular in Python circles today, can help us add progress bars to any code logic that has a circular iteration process, thus helping us to perceive the process of code execution.
2 6 useful features in tqdm 2.1 autobook automatic switching progress bar style
Those of you who have used tqdm know that it can be used in both regular terminals and jupyter-style editors, where it will render in a more aesthetically pleasing form, whereas in the past we usually needed to import tqdm separately using from tqdm import tqdm in regular terminals and from tqdm.notebook import tqdm in jupyter-style editors.
In recent versions of tqdm, new features of experimental nature have been introduced, so that we only need to import tqdm uniformly through from tqdm.autonotebook import tqdm, and we can adaptively detect different operating environments to automatically control the display:
2.2 Delay rendering progress bar
Sometimes we hope that when the loop process is executed quickly, we can not print the progress bar. After all, the main purpose of the progress bar is to monitor the long-running process. In this case, we can add the parameter delay to tqdm() to set the number of seconds of delay. When the actual running time of the loop process is less than delay, there is no need to print the redundant iteration process:
2.3 Custom Progress Bar Color
By setting the parameter color for tqdm(), you can pass in a variety of common color format values, especially in the jupyter class editor:
2.4 Autonomous control of progress upper limit
In some cases, the object we pass tqdm() cannot be calculated in advance to get the upper limit of progress in the iteration process, such as itertuples() of the data box in pandas. In this case, we can use the total parameter to preset the upper limit ourselves:
2.5 Alternatives for enumerate, zip, and map
In addition to the regular loop process in Python, there are several built-in functions that also have iterative loop properties, and tqdm in order to facilitate us to add progress bars to these atypical loop processes, we have also developed three APIs separately, namely enumerate, tzip, and tmap, to replace enumerate, zip, and map:
2.6 Set the progress bar to "run out"
When we want to add progress bar monitoring to a multi-layer loop process, the conventional use of tqdm() directly for each layer will result in too many progress bars printed, which is not conducive to observing the progress process.
By using trange() in tqdm.auto, we can set the parameter leave=False to make our corresponding progress bar automatically disappear when loaded to the head, such as the example shown in the following animation:
At this point, I believe that everyone has a deeper understanding of "what are the practical skills of the progress bar in Python", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.