2
1

More than 1 year has passed since last update.

[Jupyter][pandas][display]計算途中の纏め表を簡単にリアルタイム表示する

Last updated at Posted at 2021-12-30

はじめに

最近Bertのfine tuneとかで計算を回してるんですが、
計算途中の途中経過を表で簡単に表示できないかなと思い
やってみたら案外簡単に出来たので投げてみます。
image.png
↑こういうの

コード

インポートします

from IPython.display import display
import pandas as pd
import time

前準備します

cols = ['Step','結果1','結果2','結果3']
df = pd.DataFrame(index=None,columns=cols)

計算時に結果を逐次与えて、表示をアップデートします

out = display(df, display_id=True)

for i in range(10):
    record = pd.Series([i,i**1,i**2,i**3],index=df.columns)
    df = df.append(record,ignore_index = True)
    out.update(df)
    time.sleep(1)

image.png
time.sleep()を入れているので1秒毎に表が更新されます

out = display(...)の所で初期表示され
out.update(df)の所で表示が更新されます

以上です

おわりに

標準的なライブラリだけで割とあっさり欲しい物が出来てちょっと気にいったので書いてみました
参考になれば幸いです

2
1
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
2
1