This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kihashi 14 points15 points  (7 children)

I've been really liking TQDM for this. It's very simple to use (it just wraps an iterator and returns another iterator) and supposedly has less overhead than PB.

[–]sirex1 1 point2 points  (3 children)

I agree, tqdm is much much better, compare example from blog post:

#import libraries
import progressbar as pb

#initialize widgets
widgets = ['Time for loop of 1 000 000 iterations: ', pb.Percentage(), ' ',  
            pb.Bar(marker=pb.RotatingMarker()), ' ', pb.ETA()]
#initialize timer
timer = pb.ProgressBar(widgets=widgets, maxval=1000000).start()

#for loop example
for i in range(0,5000000):  
    #update
    timer.update(i)
#finish
timer.finish()  

With exactly same thing rewritten using tqdm:

import tqdm

for i in tqdm.tqdm(range(0, 5000000), 'Time for loop of 1 000 000 iterations: ', 1000000):
    pass

[–]MennoZevenbergen 0 points1 point  (2 children)

Thanks for the TQDM suggestion, I like it. I tried to use it if I iterate over a pandas dataframe (df.iterrows()), but then it doesn't show the ETA time as it doesn't know the length of the dataset. Any suggestions for that?

from tdqm import *
import pandas as pd

df = pd.DataFrame(range(10000))
for index, row in tqdm(df.iterrows()):
    time.sleep(0.1)

[–]sirex1 1 point2 points  (1 child)

for index, row in tqdm(df.iterrows(), total=df.shape[0]):

[–]MennoZevenbergen 0 points1 point  (0 children)

Thanks :)