LoginSignup
31
22

More than 3 years have passed since last update.

JupyterLabでtqdmでプログレスバー表示して処理状況(学習状況)の可視化

Last updated at Posted at 2018-05-28

JupyterLab-Google-Chrome-2018_05_28-14_55_11.gif

背景

JupyterNotebookでtqdmの記事はたくさんあるが、JupyterLabでtqdmは(特に日本語記事は)なかったため、記録として書き残しておく。

やりたいこと

  • JupyterLabで、tqdmを使って処理状況(≒学習状況)の可視化。

  • forのループではなく、pandasのapply(ラムダ関数)にも適用したい。

問題

  • 1, 下記のエラーが出る。
    AttributeError: 'function' object has no attribute 'pandas'

  • 2, Error displaying widgetと出る。 image.png

対策

# script有効化
jupyter nbextension enable --py --sys-prefix widgetsnbextension

# ipyvolumeのインストール
jupyter labextension install ipyvolume

# jupyterlab-managerのインストール(要:バージョン確認!)
jupyter labextension install @jupyter-widgets/jupyterlab-manager@1.0
  • jupyterlab-managerのバージョンは、JupyterLabのバージョンを確認してから、ここで確認する。

  • JupyterLabのバージョンは、JupyterLab起動後、Help -> About JupyterLab Betaで確認できる。

  • コード例1
from tqdm._tqdm_notebook import tqdm_notebook
import numpy as np

# tqdm_notebookで囲うだけ
for a in tqdm_notebook(np.arange(1, 10000000, 1)):
    # ここに処理
    a = a
  • コード例2
# pandasのapplyへ適用
# import
from tqdm._tqdm_notebook import tqdm_notebook

# set description
tqdm_notebook.pandas(desc="Processing:")

# apply
df['hoge'] = df['hoge'].progress_apply(lambda x:  x + 1)
  • 表示される image.png
31
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
22