tqdm模块
tqdm 是 Python 进度条库。
tqdm库下面有2个类我们经常使用:
1.
2.
可以在 Python 长循环中添加一个进度提示信息用法:tqdm(iterator)
trange(i) 是 tqdm(range(i)) 的简单写法。
可以总结为三个方法:
方法一:
# 方法1:
import time
from tqdm import tqdm for i in tqdm(range()):
time.sleep(0.01) 方法1+:
import time
from tqdm import trange for i in trange():
time.sleep(0.01)
结果如下:
%| | / [:<?, ?it/s]
%|█ | / [:<:, .10it/s]
%|██ | / [:<:, .77it/s]
%|███ | / [:<:, .71it/s]
%|████ | / [:<:, .49it/s]
%|█████ | / [:<:, .56it/s]
%|██████ | / [:<:, .82it/s]
%|███████ | / [:<:, .57it/s]
%|████████ | / [:<:, .44it/s]
%|█████████ | / [:<:, .82it/s]
%|██████████| / [:<:, .81it/s]
%|██████████| / [:<:, .91it/s]
%| | / [:<?, ?it/s]
%|█ | / [:<:, .74it/s]
%|██ | / [:<:, .20it/s]
%|███ | / [:<:, .83it/s]
%|████ | / [:<:, .83it/s]
%|█████ | / [:<:, .57it/s]
%|██████ | / [:<:, .90it/s]
%|███████ | / [:<:, .88it/s]
%|████████ | / [:<:, .00it/s]
%|█████████ | / [:<:, .69it/s]
%|██████████| / [:<:, .76it/s]
%|██████████| / [:<:, .71it/s]
方法二:可以为进度条设置描述
import time
from tqdm import tqdm pbar = tqdm(["a", "b", "c", "d"])
for char in pbar:
# 设置描述
pbar.set_description("Processing %s" % char)
time.sleep(0.2)
%| | / [:<?, ?it/s]
Processing a: %| | / [:<?, ?it/s]
Processing a: %|██▌ | / [:<:, .99it/s]
Processing b: %|██▌ | / [:<:, .99it/s]
Processing b: %|█████ | / [:<:, .99it/s]
Processing c: %|█████ | / [:<:, .99it/s]
Processing c: %|███████▌ | / [:<:, .99it/s]
Processing d: %|███████▌ | / [:<:, .99it/s]
Processing d: %|██████████| / [:<:, .99it/s]
Processing d: %|██████████| / [:<:, .99it/s]
方法三:手动更新
import time
from tqdm import tqdm # 一共200个,每次更新10,一共更新20次
with tqdm(total=200) as pbar:
pbar.set_description("Processing")
for i in range(20):
pbar.update(10)
time.sleep(0.1) #方法2:
pbar = tqdm(total=200)
for i in range(20):
pbar.update(10)
time.sleep(0.1)
pbar.close()
0%| | 0/200 [00:00<?, ?it/s]
Processing: 0%| | 0/200 [00:00<?, ?it/s]
Processing: 10%|█ | 20/200 [00:00<00:00, 198.53it/s]
Processing: 15%|█▌ | 30/200 [00:00<00:01, 152.68it/s]
Processing: 20%|██ | 40/200 [00:00<00:01, 131.50it/s]
Processing: 25%|██▌ | 50/200 [00:00<00:01, 119.83it/s]
Processing: 30%|███ | 60/200 [00:00<00:01, 112.82it/s]
Processing: 35%|███▌ | 70/200 [00:00<00:01, 108.39it/s]
Processing: 40%|████ | 80/200 [00:00<00:01, 105.48it/s]
Processing: 45%|████▌ | 90/200 [00:00<00:01, 103.54it/s]
Processing: 50%|█████ | 100/200 [00:00<00:00, 102.21it/s]
Processing: 55%|█████▌ | 110/200 [00:01<00:00, 101.32it/s]
Processing: 60%|██████ | 120/200 [00:01<00:00, 100.70it/s]
Processing: 65%|██████▌ | 130/200 [00:01<00:00, 100.27it/s]
Processing: 70%|███████ | 140/200 [00:01<00:00, 100.17it/s]
Processing: 75%|███████▌ | 150/200 [00:01<00:00, 100.00it/s]
Processing: 80%|████████ | 160/200 [00:01<00:00, 99.78it/s]
Processing: 85%|████████▌ | 170/200 [00:01<00:00, 99.75it/s]
Processing: 90%|█████████ | 180/200 [00:01<00:00, 99.60it/s]
Processing: 95%|█████████▌| 190/200 [00:01<00:00, 99.71it/s]
Processing: 100%|██████████| 200/200 [00:01<00:00, 99.68it/s]
Processing: 100%|██████████| 200/200 [00:02<00:00, 99.39it/s] 0%| | 0/200 [00:00<?, ?it/s]
10%|█ | 20/200 [00:00<00:00, 198.60it/s]
15%|█▌ | 30/200 [00:00<00:01, 152.73it/s]
20%|██ | 40/200 [00:00<00:01, 131.51it/s]
25%|██▌ | 50/200 [00:00<00:01, 119.83it/s]
30%|███ | 60/200 [00:00<00:01, 112.82it/s]
35%|███▌ | 70/200 [00:00<00:01, 108.38it/s]
40%|████ | 80/200 [00:00<00:01, 105.37it/s]
45%|████▌ | 90/200 [00:00<00:01, 103.56it/s]
50%|█████ | 100/200 [00:00<00:00, 102.19it/s]
55%|█████▌ | 110/200 [00:01<00:00, 101.52it/s]
60%|██████ | 120/200 [00:01<00:00, 100.93it/s]
65%|██████▌ | 130/200 [00:01<00:00, 100.43it/s]
70%|███████ | 140/200 [00:01<00:00, 100.08it/s]
75%|███████▌ | 150/200 [00:01<00:00, 100.04it/s]
80%|████████ | 160/200 [00:01<00:00, 99.90it/s]
85%|████████▌ | 170/200 [00:01<00:00, 99.92it/s]
90%|█████████ | 180/200 [00:01<00:00, 99.81it/s]
95%|█████████▌| 190/200 [00:01<00:00, 99.86it/s]
100%|██████████| 200/200 [00:01<00:00, 99.78it/s]
100%|██████████| 200/200 [00:02<00:00, 99.47it/s]
tqdm模块的更多相关文章
- hdf5文件、tqdm模块、nunique、read_csv、sort_values、astype、fillna
pandas.DataFrame.to_hdf(self, path_or_buf, key, **kwargs): Hierarchical Data Format (HDF) ,to add an ...
- [Python]-tqdm模块-给for循环加上进度条
import tqdm 使用tqdm模块,可以在漫长的for循环加上一个进度条,显示当前进度百分比. 将tqdm写在迭代器之外即可:tqdm(iterator) for i in tqdm(range ...
- (数据科学学习手札53)Python中tqdm模块的用法
一.简介 tqdm是Python中专门用于进度条美化的模块,通过在非while的循环体内嵌入tqdm,可以得到一个能更好展现程序运行过程的提示进度条,本文就将针对tqdm的基本用法进行介绍. 二.基本 ...
- python的tqdm模块
Tqdm 是一个快速,可扩展的Python进度条,可以在 Python 长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator). 根据要求安装依赖即可. 可以很方便的在 ...
- python的tqdm模块介绍
https://www.jianshu.com/p/b27318efdb7b Tqdm 是 Python 进度条库,可以在 Python 长循环中添加一个进度提示信息用法:tqdm(iterator) ...
- python实现进度条
先说一下文本系统的控制符: \r: 将光标移动到当前行的首位而不换行: \n: 将光标移动到下一行,并不移动到首位: \r\n: 将光标移动到下一行首位. 环境: root@ubuntu16:/ale ...
- 万能的Python,还能用来制作高大上的进度条?
对于开发或者运维来说,使用Python去完成一些跑批任务,或者做一些监控事件是非常正常的情况.那么如何有效的监控任务的进度,除了在任务中加上log外,还能不能有另一种方式来了解任务进展到哪一步了呢? ...
- 【Python】给程序加个进度条
对于开发或者运维来说,使用 Python 去完成一些跑批任务,或者做一些监控事件是非常正常的情况.那么如何有效地监控任务的进度?除了在任务中加上 Log 外,还能不能有另一种方式来了解任务进展到哪一步 ...
- 用 Python 给程序加个进度条,让你的看起来更炫酷?
对于开发或者运维来说,使用 Python 去完成一些跑批任务,或者做一些监控事件是非常正常的情况.那么如何有效地监控任务的进度?除了在任务中加上 Log 外,还能不能有另一种方式来了解任务进展到哪一步 ...
随机推荐
- 【Python】【demo实验5】【练习实例】【多个数字组合成不重复三位数】
题目:有四个数字:1.2.3.4,能组成多少个互不相同且无重复数字的三位数?各是多少? 程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. 程序源代码 ...
- Kudu建表语句
--建表CREATE TABLE kudu_testdb.perf_test_t1( id string ENCODING PLAIN_ENCODING COMPRESSION SNAPPY, int ...
- 小记--------spark的Master主备切换机制原理分析及源码分析
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABfEAAAJwCAYAAAAp7ysfAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw
- 我的第一个Java博客
1.2019 11.23 Alone in Beijing;
- ArrayList与LinkedList的区别,如何减少嵌套循环的使用
如果要减少嵌套循环的使用: 我们可以将需要在二重循环里面判断的条件放在一个Map的key里面: 在判断的时候只需要进行key是否存在,然后操作接下来的步骤: 这样子就会减少二重循环了,不会发生循环n* ...
- [HAOI2010]软件安装 题解
题面 这道题比较显然地,是一道树形背包: 但是会有环,怎么办呢? 缩点!tarjan缩点! 然后在新图上跑树形背包就可以AC了 #include <bits/stdc++.h> #defi ...
- Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)
题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...
- spring boot 2.0 提示 No primary or default constructor found for interface Pageable 解决办法
在SpringBoot 2.0 以前,我们会配置以下类 @Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter ...
- 使用iview ui库 [vue/no-parsing-error] Parsing error: x-invalid-end-tag报错
打开设置,搜索“vetur.validation.template”,设置完毕之后记得重启vscode 如果不行请使用下边方法 一. 问题日志 ✘ https://google.com/#q=vue% ...
- Lua格式讲解
firstValue = "This is a string value"; -- 这是一个变量的定义,变量定义不需要任何标记,这个是全局变量 print("helloW ...