2016-08-09 13 views
3

jupyter-notebookでプログレスバーを実装するにはどうすればよいですか?進捗バーを実装するには

私はこれをやった:

私はものをプリントアウトするためにしたループへのアクセス権を持っているときに最適です
count = 0 
max_count = 100 
bar_width = 40 
while count <= max_count: 
    time.sleep(.1) 
    b = bar_width * count/max_count 
    l = bar_width - b 
    print '\r' + u"\u2588" * b + '-' * l, 
    count += 1 

。しかし、誰かが非同期的に何らかのプログレスバーを実行するために巧妙なものを知っていますか?

答えて

5

を見てみましょう(this以下)ソリューションです。

from ipywidgets import FloatProgress 
from IPython.display import display 
import time 

max_count = 100 

f = FloatProgress(min=0, max=max_count) # instantiate the bar 
display(f) # display the bar 

count = 0 
while count <= max_count: 
    f.value += 1 # signal to increment the progress bar 
    time.sleep(.1) 
    count += 1 
2

tqdmを試すことができます。コード例:

# pip install tqdm 
from tqdm import tqdm_notebook 

# works on any iterable, including cursors. 
# for iterables with len(), no need to specify 'total'. 
for rec in tqdm_notebook(positions_collection.find(), 
         total=positions_collection.count(), 
         desc="Processing records"): 
    # any code processing the elements in the iterable 
    len(rec.keys()) 

デモ: https://youtu.be/T0gmQDgPtzY

関連する問題