A Brief Introduction of the Tqdm Module in Python

news2024/9/26 3:22:54
DateAuthorVersionNote
2024.02.28Dog TaoV1.0Release the note.

文章目录

  • A Brief Introduction of the Tqdm Module in Python
    • Introduction
      • Key Features
      • Installation
    • Usage Examples
      • Basic Usage
      • Advanced Usage

A Brief Introduction of the Tqdm Module in Python

Introduction

Tqdm is a versatile Python library that provides a fast, extensible progress bar for loops and other iterable processes. The name tqdm is derived from the Arabic word “taqaddum” (تقدّم), meaning “progress,” and is pronounced as “ta-qe-dum.” Its simplicity and efficiency have made it a go-to choice for adding progress indicators to Python code, especially in data processing, file I/O, and long-running computations.

Key Features

  • Easy to Use: Tqdm can be added to your loops with minimal code changes, instantly providing visual feedback on the progress.
  • Highly Customizable: While simple to implement with default settings, tqdm also offers a wide range of customization options, including custom messages, progress bar formatting, and manual control over the progress updates.
  • Lightweight with Minimal Dependencies: It is designed to be lightweight and requires no heavy dependencies, making it suitable for various projects.
  • Versatile: Works with loops, iterable objects, and can even be used to track progress in pandas operations with tqdm.pandas().

Installation

  • Using pip

To install tqdm using pip, open your terminal (or command prompt/PowerShell in Windows) and run the following command:

pip install tqdm

If you are working in a virtual environment (which is recommended to avoid conflicts between different projects), make sure it is activated before running the pip install command.

  • Using conda

To install tqdm using conda, you should have Anaconda or Miniconda installed on your system. Open your Anaconda Prompt (or terminal in Linux/macOS) and run the following command:

conda install -c conda-forge tqdm

Using the -c conda-forge flag specifies that conda should install tqdm from the conda-forge channel, which is a community-maintained collection of conda packages.

Usage Examples

Basic Usage

The most common use of tqdm is to wrap it around any iterable in a for loop.

from tqdm import tqdm
import time

for i in tqdm(range(1000)):
    # Simulated task
    time.sleep(0.001)

The output example:

在这里插入图片描述

Advanced Usage

  • Customization: You can customize the progress bar with various parameters such as desc (description), total, leave, ncols (width), unit, and more.
for i in tqdm(range(100), desc="Loading", ascii=False, ncols=75):
    time.sleep(0.01)
  • Manual Updates: For tasks that don’t fit neatly into a loop, tqdm can be manually updated.
pbar = tqdm(total=100)
for i in range(10):
    time.sleep(0.1)
    pbar.update(10)  # Manually update the progress bar by 10
pbar.close()

The output example:

在这里插入图片描述

  • Integration with Pandas: Tqdm can be integrated with Pandas operations using tqdm.pandas(). This is particularly useful for applying functions to DataFrame columns or rows and visualizing the progress.
import pandas as pd
from tqdm import tqdm
tqdm.pandas()

df = pd.DataFrame({'x': range(10000)})
df['y'] = df['x'].progress_apply(lambda x: x**2)

The output example:

在这里插入图片描述

  • Working with Concurrent Futures: Tqdm can also be used with concurrent programming modules like concurrent.futures for tracking the progress of asynchronous tasks.
from concurrent.futures import ThreadPoolExecutor, as_completed

with ThreadPoolExecutor(max_workers=5) as executor:
    futures = [executor.submit(time.sleep, 0.1) for _ in range(100)]
    for f in tqdm(as_completed(futures), total=len(futures)):
        pass

The output example:

在这里插入图片描述

Tqdm’s simplicity, combined with its powerful features, makes it an invaluable tool for enhancing the user experience in command-line applications and Jupyter notebooks by providing clear and customizable progress indications.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1486485.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【详识JAVA语言】面向对象程序三大特性之三:多态

多态 多态的概念 多态的概念:通俗来说,就是多种形态,具体点就是去完成某个行为,当不同的对象去完成时会产生出不同的状态。 多态实现条件 在java中要实现多态,必须要满足如下几个条件,缺一不可&#xf…

golang实现openssl自签名双向认证

第一步:生成CA、服务端、客户端证书 1. 生成CA根证书 生成CA证书私钥 openssl genrsa -out ca.key 4096创建ca.conf 文件 [ req ] default_bits 4096 distinguished_name req_distinguished_name[ req_distinguished_name ] countryName …

【Web】速谈FastJson反序列化中JdbcRowSetImpl的利用

目录 简要原理分析 exp 前文:【Web】速谈FastJson反序列化中TemplatesImpl的利用 简要原理分析 前文的TemplatesImpl链存在严重限制,即JSON.parseObject()需要开启Feature.SupportNonPublicField fastjson的第二条链JdbcRowSetImpl,主要…

(亲测可用)Adobe Photoshop 2024下载与安装

背景介绍:Adobe Photoshop 2024 是全球最受欢迎的图像编辑软件之一,2024年的版本带来了一系列令人印象深刻的功能: AI增强的自动选择和蒙版工具:现在,用户可以更轻松地选择和处理复杂的图像元素。更多的3D渲染功能&…

2023.3.3周报

目录 摘要 一、文献阅读 1、题目 2、摘要 3、模型架构 4、文献解读 一、Introduction 二、实验 三、结论 二、PINN 一、PINN比传统数值方法有哪些优势 二、PINN方法 三、正问题与反问题 三、PINN实验 一、数学方程 二、模型搭建 总结 摘要 本周我阅读了一篇…

(二)逻辑回归与交叉熵--九五小庞

什么是逻辑回归 线性回归预测的是一个连续值,逻辑回归给出的“是”和“否”的回答 Singmoid sigmoid函数是一个概率分布函数,给定某个输入,它将输出为一个概率值 逻辑回归损失函数 平方差所惩罚的是与损失为同一数量级的情形&#xff0…

数据结构——基本术语和概念

目录 1.数据 2.数据元素 3.数据项 4.数据对象 数据元素与数据对象 5.数据结构 1.逻辑结构 逻辑结构的种类 划分方式1 1.线性结构 2.非线性结构 ​ 划分方式2——四类基本逻辑结构 2.物理结构(存储结构) 1.顺序存储结构 2.链接存储结构 3…

软件实例,佳易王账单账本记账汇总统计管理系统软件教程

软件实例,佳易王账单账本记账汇总统计管理系统软件教程 一、前言 以下软件程序教程 以 佳易王账单记账汇总统计管理系统软件V17.0为例说明 软件文件下载可以点击最下方官网卡片——软件下载——试用版软件下载 账单可以记录 1、收入明细 2、支出明细 3、客户…

JetCache源码解析——API实现(持续更新中……)

在JetCache中不仅可以通过在类和接口的函数上使用注解Cached、CacheUpdate和CacheInvalidate等实现缓存加载、更新和删除操作,也支持通过调用API接口的形式来实现缓存的加载、更新和删除操作。 缓存接口 缓存接口的定义如下: /*** 缓存接口&#xff0…

15.网络游戏逆向分析与漏洞攻防-网络通信数据包分析工具-发送通信数据包至分析工具

上一个内容:14.数据包分析工具界面与通信设计 码云地址(master 分支):https://gitee.com/dye_your_fingers/titan 码云版本号:2d6491e3c51a1a7ab4da0ee6dc4cf566a80fd6e1 代码下载地址,在 titan 目录下&…

LeetCode--42

42. 接雨水 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 示例 1: 输入:height [0,1,0,2,1,0,1,3,2,1,2,1] 输出:6 解释:上面是由数组 [0,1,0,2,1,0,1,…

WPF中如何使用HandyCotrol控件库

HandyControl介绍 HandyControl是一个开源的WPF(Windows Presentation Foundation)控件库,旨在简化WPF应用程序的开发过程并提高用户界面的美观程度和易用性。它提供了丰富的控件、样式和模板,可以帮助开发人员快速构建出现代化的…

CUDA 中的线程组织

明朝那些事中有一句话:我之所以写徐霞客是想告诉你,所谓千秋霸业万古流芳,与一件事相比,其实都算不了什么,这件事情就是——用你喜欢的方式度过一生。 我们以最简单的 CUDA 程序:从 GPU 中输出 Hello World…

oracle RAC 集群归档模式的关闭和开启(适用于11g/12g/18c/19c)

oracle RAC 集群归档模式的关闭和开启(适用于11g/12g/18c/19c) oracle RAC 集群归档模式的关闭(适用于11g/12g/18c/19c) 1、登录数据库:执行alter system set cluster_database false scopespfile;2、关闭node2数据…

Vue--》打造简易直播应用平台项目实战

今天开始使用 vue3 + ts 搭建一个简易直播应用平台项目,因为文章会将项目的每一个地方代码的书写都会讲解到,所以本项目会分成好几篇文章进行讲解,我会在最后一篇文章中会将项目代码开源到我的github上,大家可以自行去进行下载运行,希望本文章对有帮助的朋友们能多多关注本…

Postman上传文件的操作方法

前言 调用某个接口,测试上传文件功能。一时间不知如何上传文件,本文做个操作记录,期望与你有益。 步骤一、设置Headers key:Content-Type value:multipart/form-data 步骤二、设置Body 选择form-data key:file下拉框选择file类型value&…

想从事数据方向职场小白看过来, 数据方面的一些英文解释

想从事数据方向职场小白看过来,一些英文名词解释 文章目录 想从事数据方向职场小白看过来,一些英文名词解释 英文类解释NoSQL:ESB:ACID :Data Vault:MDM:OLAP:SCD:SBA:MP…

鸿蒙Harmony应用开发—ArkTS声明式开发(通用属性:图像效果)

设置组件的模糊、阴影、球面效果以及设置图片的图像效果。 说明: 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 blur blur(value: number, options?: BlurOptions) 为组件添加内容模糊效果。 卡片能力&am…

Day11:信息打点-Web应用企业产权指纹识别域名资产网络空间威胁情报

目录 Web信息收集工具 业务资产-应用类型分类 Web单域名获取-接口查询 Web子域名获取-解析枚举 Web架构资产-平台指纹识别 思维导图 章节知识点: Web:语言/CMS/中间件/数据库/系统/WAF等 系统:操作系统/端口服务/网络环境/防火墙等 应用…

047 内部类

成员内部类用法 /*** 成员内部类** author Admin*/ public class OuterClass {public void say(){System.out.println("这是类的方法");}class InnerClass{public void say(){System.out.println("这是成员内部类的方法");}}public static void main(Stri…