Jupyter notebookで見やすい方のtqdmを使うの巻
- 2020.06.09
- Python 使いかた備忘録
- Jupyter notebook, python, tqdm

はじめに
Jupyter notebookでプログレスバーを使うためにtqdmを入れてみたものの、
ネストしたfor文に普通に適用すると進捗状況がずらずら表示されてなんかうーんな感じです。
これを見やすくできる方法があるとのことだったのでそうしてみたら見やすくなりましたよ、という話。
tqdmのインストール
ターミナルからpipでtqdmをインストールしてあります(パッケージ管理をpipでやっているので)。
pip install tqdm
にて。
ごちゃごちゃ出ちゃうのよ
from tqdm import tqdm
で、
ネストしたfor文に普通に適用すると、状況が更新されるたびに出力されるらしく、ずらずらずらずらと出てしまって見にくいのよ。。。

ごちゃごちゃを回避するためには、tqdm.notebookを使うといい
先ほどのただのtqdmではなくtqdm.notebookを使います。
from tqdm.notebook import tqdm
にて。ずいぶんスッキリ見やすくなり、見た目も良くなります。

leave = Falseとしとくともっとスッキリになりますね。

なお、pandasのデータでtqdmを使うためには
tqdm.pandas()
と打っておけば良いです。
ちなみに
今はtqdm.notebookを使うらしい
ちょっと前まではtqdm_notebookというやつだったみたいで、参考にしたサイトなどでも、
from tqdm import tqdm_notebook as tqdm
などと呼び出してtqdm_notebookとコマンド打って使ってたけど、以下のwarningが出ます。まだtqdm_notebookでも実行できるけど、
いつからかtqdm.notebookに変わっていて、ver.5.0.0では完全移行なのね。。。
TqdmDeprecationWarning: This function will be removed in tqdm==5.0.0 Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`
HBox・・・が出てプログレスバーが出ないとき
tqdmで実行した時に、
HBox(children=(FloatProgress(value=0.0, description='1st loop', max=4.0, style=ProgressStyle(description_width…
みたいなのが出てプログレスバーが出てこない時は、ipywidgetsでの設定が足りてないよう。
ターミナルで、
pip install ipywidgets
でインストールしておいてから、
jupyter nbextension enable --py widgetsnbextension
と打っておいて、Jupyter notebookを立ち上げます。
ワタシの場合はwheelというやつが無いと言われたのでさらにそれもpipで入れました。
pip install wheel
にて。これでうまく動きました。
少し快適になりました。めでたしめでたし。
ちょっと広告です
https://business.xserver.ne.jp/

https://www.xdomain.ne.jp/

★LOLIPOP★

.tokyo

MuuMuu Domain!

Python; 3.7.2
Jupyter ; 1.0.0
macOS; Catalina version 10.15.4
で実施しました。
主に参考にしたサイト。ありがとうございます。
https://towardsdatascience.com/progress-bars-in-python-and-pandas-f81954d33bae
https://ipywidgets.readthedocs.io/en/latest/user_install.html
このブログはエックスサーバー


WordPressを使うならロリポップ!
簡単インストール完備で楽々スタート!

世界にたった一つ、あなただけのドメインを登録しよう!
格安ドメイン取得サービス─ムームードメイン─
