python输出进度条 tqdm_python-tqdm进度条的使用

测试环境:win10+py3+jupyter notebook

主要作用:循环时,显示循环的百分比进度及文字说明。

安装:cmd终端命令行输入 pip3 install tqdm

代码示例:

from tqdm import tqdm

import time

import numpy as np

bar = tqdm(list(‘ABCDEFGH’))

for each in bar:

”’添加进度文字说明,当然也可以不添加文字描述”’

bar.set_description(‘正在执行任务:{}’.format(each))

time.sleep(np.random.random())

”’关闭,不然下次进度条使用会多行显示”’

bar.close()

图示:

python输出进度条 tqdm_python-tqdm进度条的使用

用pandas写一个合并excel工作簿试试

import pandas as pd

import glob

import os

os.chdir(‘d:/桌面/’)

”’模糊搜索’桌面’文件夹下的excel文件”’

file_list = glob.glob(‘*.xlsx’)

df = pd.read_excel(file_list[0])

bar = tqdm(range(1,len(file_list)-1))

for each in bar:

bar.set_description(“正在合并文件:{}”.format(file_list[each]))

df1 = pd.read_excel(file_list[each])

df = df.append(df1)

”’导出合并的excel文件”’

df.to_excel(‘concat_book.xlsx’,index=False)

print(‘Concat Done!’)

Original: https://blog.csdn.net/weixin_28795975/article/details/114466696
Author: 邓潍
Title: python输出进度条 tqdm_python-tqdm进度条的使用

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/680031/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球