原文:

https://segmentfault.com/a/1190000016059726

 

当然,首先我们得载入模块,在notebook中使用tqdm带的基于Js显示的进度条前,请务必检查是否安装ipywidgets模块。

from tqdm import tqdm_notebook, _tqdm_notebook
_tqdm_notebook.tqdm_notebook.pandas()

其中第一行载入的两个方法的作用分别是:

  • tqdm_notebook:用来包装任何可以iterable的对象,在使用其元素进行运算结束后统计时间。
  • _tqdm_notebook:其中含有模块可以处理pandas的对象。

第二行则是重载pandas里面的对象,提供可以展示精度条的方法。

下面我们可以尝试直接使用tqdm_notebook包裹iterable对象来展示进度条,效果如下:

a = list(range(1, 10000))
b = range(1, 10000)
_ = [(lambda x: x+1)(i) for i in tqdm_notebook(a)]
_ = [(lambda x: x+1)(i) for i in tqdm_notebook(b)]

 

相关文章:

  • 2021-06-04
  • 2021-09-04
  • 2022-12-23
  • 2021-09-23
  • 2021-05-27
  • 2021-06-28
  • 2021-12-09
猜你喜欢
  • 2021-05-21
  • 2021-06-05
  • 2021-11-23
  • 2021-09-27
  • 2022-12-23
  • 2021-08-25
  • 2021-11-09
相关资源
相似解决方案