Python:使用 tqdm 跟踪作业进度

Python: track job progress using tqdm

我正在使用以下代码来跟踪作业进度:

from tqdm import tqdm, tqdm_pandas
tqdm.pandas(tqdm())

my_df['target'] = my_df.progress_apply(lambda x: my_fun(x), axis = 1)

然后代码提供如下进度跟踪:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|██        | 1/5 [00:06<00:26,  6.62s/it]
215it [00:06,  4.63s/it]                     
1062it [00:06,  3.24s/it]
1976it [00:06,  2.27s/it]
2893it [00:07,  1.59s/it]
3811it [00:07,  1.11s/it]
4720it [00:07,  1.28it/s]
5650it [00:07,  1.83it/s]
6585it [00:07,  2.62it/s]
7520it [00:07,  3.74it/s]
8444it [00:07,  5.35it/s]
9378it [00:07,  7.64it/s]
10311it [00:07, 10.90it/s]
11218it [00:07, 15.57it/s]
12111it [00:08, 22.22it/s]
13004it [00:08, 31.70it/s]
13832it [00:08, 45.20it/s]
14618it [00:08, 64.36it/s]
15404it [00:08, 91.62it/s]
16149it [00:08, 129.91it/s]
16870it [00:08, 184.16it/s]
17560it [00:08, 259.28it/s]
18315it [00:08, 365.02it/s]
19162it [00:09, 512.00it/s]
19891it [00:09, 706.09it/s]
       :
       :

我想知道是否可以每 5 秒打印一次信息而不是每秒 10 次输出?非常感谢!

是的,只需使用 mininterval 参数:

tqdm.pandas(tqdm, mininterval=5)