In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to make a progress bar in Jupyter notebook. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1. Ordinary progress bar
You can do your own statistical calculation during the iterative run of the code, and use the format string to output the progress of the code.
Import sysimport timedef progress_bar (): for i in range (1,101): print ("\ r", end= "") print ("Download progress: {}%:" .format (I), "▋" * (I / / 2), end= ") sys.stdout.flush () time.sleep (0.05) progress_bar ()
two。 Progress bar with time
Import the time module to calculate the code run time, plus the code iteration progress use the format string to output the code run progress
Import timescale = 50print ("start running" .center (scale / / 2, "-")) start = time.perf_counter () for i in range (scale + 1): a = "*" * I b = "." * (scale-I) c = (I / scale) * 100 dur = time.perf_counter ()-start print ("\ r {: ^ 3.0f}% [{}-> {}] {: .2f} s" .f ormat (cbot) End = ") time.sleep (0.1) print ("\ n "+" run end ".center (scale / / 2,"-"))
3. Tpdm progress bar
This is a toolkit for generating progress bars, which can be downloaded at the terminal using pip, and of course you can change the style of progress bars.
From time import sleepfrom tqdm import tqdm# also here, tqdm is one of the most commonly used methods in this progress bar # storing an iterable object for i in tqdm (range (1,500)): # simulating your task sleep (0.01) sleep (0.5)
Reference: related documentation: https://tqdm.github.io/
4. Progress progress bar
You only need to define the number of iterations, the type of progress bar and inform the progress bar at each iteration. The specific code example is as follows
# pip install progressfrom alive_progress import alive_baritems = range # retrieve your set of itemswith alive_bar (len (items)) as bar: # declare your expected total for item in items: # iterate as usual # process each item bar () time.sleep
Reference: related documentation: https://pypi.org/project/progress/1.5/
5. Alive_progress progress bar
As the name implies, this library can make the progress bar lively. It has some more animated effects than the progress bar we have seen before. You need to download it using pip. The code example is as follows:
# pip install progressfrom alive_progress import alive_baritems = range # retrieve your set of itemswith alive_bar (len (items)) as bar: # declare your expected total for item in items: # iterate as usual # process each item bar () time.sleep
Reference: related documentation: https://github.com/rsalmei/alive-progress
6. Visual progress bar
Using PySimpleGUI to get the graphical progress bar, we can add a simple line of code to get the graphical progress bar in the command line script, which is also downloaded using pip. The code example is as follows
# pip install PySimpleGUIimport PySimpleGUI as sgimport timemylist = [1 pip install PySimpleGUIimport PySimpleGUI as sgimport timemylist 2 3 key-' 4 5 5 6 7 8] for I, item in enumerate (mylist): sg.one_line_progress_meter ('This is my progress meterial, item1, len (mylist),'-key-') time.sleep (1)
Reference: one row of data
1. Ordinary progress bar
# ordinary progress bar import sysimport timedef progress_bar (): for i in range (1101): print ("\ r", end= "") print ("Download progress: {}%:" .format (I), "▋" * (I / / 2), end= ") sys.stdout.flush () time.sleep (0.05) progress_bar ()
two。 Progress bar with time
# Progress bar with time import timescale = 50print ("execution starts Pray not to report wrong ".center (scale / / 2,"-") start = time.perf_counter () for i in range (scale + 1): a =" * "* I b =". "* (scale-I) c = (I / scale) * 100 dur = time.perf_counter ()-start print ("\ r {: ^ 3.0f}% [{}-> {}] {: .2f} s ".f ormat End = "") time.sleep (0.1) print ("\ n" + "end of execution Fortunately ".center (scale / / 2,"-"))
3.tpdm progress bar
# tpdm progress bar from time import sleepfrom tqdm import tqdm# the same here, tqdm is one of the most commonly used methods in this progress bar # store an iterable object for i in tqdm (range (1,500)): # simulate your task sleep (0.01) sleep (0.5)
4. Progress progress bar
# progress progress bar import timefrom progress.bar import IncrementalBarmylist = [1 Countdown', max 2 time.sleep 3 4 5 5 6 7 8] bar = IncrementalBar ('Countdown', max = len (mylist)) for item in mylist: bar.next () time.sleep (1) bar.finish ()
5. Alive_progress progress bar
# alive_progress progress bar from alive_progress import alive_baritems = range # retrieve your set of itemswith alive_bar (len (items)) as bar: # declare your expected total for item in items: # iterate as usual # process each item bar () time.sleep
6. Visual progress bar
# Visualization progress bar import PySimpleGUI as sgimport timemylist = [1 This is my progress 2, 4, 5, 6, 7, 8] for I, item in enumerate (mylist): sg.one_line_progress_meter ('This is my progress meterials, item1, len (mylist),'-key-') time.sleep (1)
On how to make a progress bar in Jupyter notebook to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.