推荐个Python进度条工具用于数据处理,不要再print出进度了
推荐个 python 的进度条工具,做数据处理的,不要再 print 出进度了-。-
tqdm
推荐个Python进度条工具用于数据处理,不要再print出进度了
10 回复
话说这玩意儿开始运行后,有其他输出的情况下是不是就把这玩意儿给覆盖了。
tqdm,就这个,没别的。直接 pip install tqdm。
用在循环上最简单,把 range 或者 list 包一下就行:
from tqdm import tqdm
import time
for i in tqdm(range(100)):
# 你的数据处理逻辑
time.sleep(0.02) # 模拟耗时操作
处理 pandas 的 apply 也方便:
import pandas as pd
from tqdm import tqdm
tqdm.pandas() # 注册一下
df = pd.DataFrame({'data': range(100)})
df['processed'] = df['data'].progress_apply(lambda x: x**2)
手动更新进度条,比如处理文件流或者自定义逻辑:
with tqdm(total=100, desc='处理文件') as pbar:
for i in range(10):
# ... 处理一部分数据
pbar.update(10) # 更新进度
总结:tqdm是标准答案。
好东西,star 了
好东西
-。- star 了,另外比较想知道这个里面动图的代码提示是什么。。。
应该是 ptpython https://github.com/jonathanslenders/ptpython
#6 多谢~
tqdm 是个好东西,pandas 里面 apply 可以用,连 jupyter notebook 也可以用
很好 star 了

