A Brief Introduction of the Tqdm Module in Python

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 timefor i in tqdm(range(1000)):# Simulated tasktime.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_completedwith 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.pswp.cn/news/717234.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/717234.shtml
英文地址,請注明出處:http://en.pswp.cn/news/717234.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

力扣hot100:42.接雨水

什么時候能用雙指針? (1)對撞指針: ①兩數和問題中可以使用雙指針,先將兩數和升序排序,可以發現規律,如果當前兩數和大于target,則右指針向左走。 ②接雨水問題中,左邊最…

【算法集訓】基礎算法:枚舉

一、基本理解 枚舉的概念就是把滿足題目條件的所有情況都列舉出來,然后一一判定,找到最優解的過程。 枚舉雖然看起來麻煩,但是有時效率上比排序高,也是一個不錯的方法、 二、最值問題 1、兩個數的最值問題 兩個數的最小值&…

Vscode安裝,ssh插件與配置

原因 發現很多新人在練習linux,可是只有windows機的時候,一般都是下載虛擬機,然后在虛擬機上安裝ubuntu等linux平臺。每次需要在linux中寫代碼,就打開ubuntu,然后在終端上用vim寫代碼,或者先編輯代碼文本&…

css實現上下左右居中

css實現子盒子在父級盒子中上下左右居中 幾種常用的上下左右居中方式 HTML代碼部分 <div class"box"><img src"./img/77.jpeg" alt"" class"img"> </div>css部分 方式一 利用子絕父相和margin:auto實現 <sty…

內存管理 -----分段分頁

分段 分段&#xff1a;程序的分段地址空間&#xff0c;分段尋址方案 兩個問題 分段 &#xff1a;是更好分離和共享 左邊是有序的邏輯地址&#xff0c;右邊是無序的物理地址&#xff0c;然后需要有一種映射的關系&#xff08;段關聯機制&#xff09; 各個程序的分配相應的地址…

Gin入門指南:從零開始快速掌握Go Web框架Gin

官網:https://gin-gonic.com/ GitHub:https://github.com/gin-gonic 了解 Gin Gin 是一個使用 Go 語言開發的 Web 框架,它非常輕量級且具有高性能。Gin 提供了快速構建 Web 應用程序所需的基本功能和豐富的中間件支持。 以下是 Gin 框架的一些特點和功能: 快速而高效:…

【簡說八股】面試官:你知道什么是IOC么?

回答 Spring的IOC&#xff08;Inversion of Control&#xff0c;控制反轉&#xff09;是Spring框架的核心特性之一。它通過將對象的創建和依賴關系的管理交給Spring容器來實現&#xff0c;降低了組件之間的耦合性&#xff0c;使得代碼更加靈活、可維護。 在傳統的開發模式中&…

Sora模型風口,普通人如何抓住-最新AI系統ChatGPT網站源碼,AI繪畫系統

一、前言說明 PandaAi創作系統是基于ChatGPT進行開發的Ai智能問答系統和Midjourney繪畫系統&#xff0c;支持OpenAI-GPT全模型國內AI全模型。本期針對源碼系統整體測試下來非常完美&#xff0c;那么如何搭建部署AI創作ChatGPT&#xff1f;小編這里寫一個詳細圖文教程吧。已支持…

邊緣計算與任務卸載基礎知識

目錄 邊緣計算簡介任務卸載簡介參考文獻 邊緣計算簡介 邊緣計算是指利用靠近數據生成的網絡邊緣側的設備&#xff08;如移動設備、基站、邊緣服務器、邊緣云等&#xff09;的計算能力和存儲能力&#xff0c;使得數據和任務能夠就近得到處理和執行。 一個典型的邊緣計算系統為…

前端按鈕動畫

效果示例 代碼示例 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"viewport" content"widthdevic…

OSCP靶場--Resourced

OSCP靶場–Resourced 考點(1.rpc枚舉 2.crackmapexec密碼噴灑&#xff0c;hash噴灑 3.ntds.dit system提取域hash 4.基于資源的約束委派攻擊rbcd) 1.nmap掃描 ## ┌──(root?kali)-[~/Desktop] └─# nmap -sV -sC -p- 192.168.188.175 --min-rate 2000 Starting Nmap 7.9…

《一篇文章搞懂git(保姆級教學)》

目錄 1.版本管理工具概念 2. 版本管理工具介紹 2.1版本管理發展簡史(維基百科) 2.1.1 SVN(SubVersion) 2.1.2 Git 3. Git 發展簡史 4. Git 的安裝 4.1 git 的下載 ?4.2 安裝 5. Git 工作流程 5.1 Git 初始化 5.2 git 流程 5.2.1 流程圖 5.2.2概念即詳解 6.Git …

IO多路復用:提高網絡應用性能的利器

&#x1f90d; 前端開發工程師、技術日更博主、已過CET6 &#x1f368; 阿珊和她的貓_CSDN博客專家、23年度博客之星前端領域TOP1 &#x1f560; 牛客高級專題作者、打造專欄《前端面試必備》 、《2024面試高頻手撕題》 &#x1f35a; 藍橋云課簽約作者、上架課程《Vue.js 和 E…

模型部署 - onnx的導出和分析 -(2) - onnx 注冊自定義算子 - 學習記錄

onnx 注冊自定義算子 第一步&#xff1a;手寫一個算子&#xff0c;然后注冊一下第二步&#xff1a;將算子放進模型定義第三步&#xff1a;利用 torch.onnx.export() 編寫onnx 導出函數 一般我們自定義算子的時候&#xff0c;有以下流程 編寫算子并注冊將算子放進模型定義利用 …

unity學習(46)——服務器三次注冊限制以及數據庫化角色信息1--數據流程

1.先找到服務器創建角色信息代碼的位置&#xff0c;UserBizImpl.cs中&#xff1a; public PlayerModel create(string accId, string name, int job) {PlayerModel[] playerModelArray this.list(accId);//list是個自建函數&#xff0c;本質通過accId來查詢if (playerModelAr…

ClickHouse數據引擎

ClickHouse 提供了多種索引引擎&#xff0c;每種引擎都有其特定的用途和特性。除了 MergeTree 引擎之外&#xff0c;以下是一些常見的索引引擎及其區別&#xff1a; MergeTree 引擎&#xff1a; 特點&#xff1a;有序、分布式、支持并發寫入和讀取。適用場景&#xff1a;適用于…

【高數】常數項級數概念與性質

下面為個人數學筆記&#xff0c;有需要借鑒即可。 一、常數項級數概念 二、常數項級數性質 三、調和級數 完。

備忘錄模式(Memento Pattern)

定義 備忘錄模式&#xff08;Memento Pattern&#xff09;是一種行為設計模式&#xff0c;它允許在不破壞封裝性的前提下捕獲一個對象的內部狀態&#xff0c;并在以后將對象恢復到該狀態。備忘錄模式通常用于實現撤銷操作&#xff08;Undo&#xff09;或歷史記錄&#xff08;H…

藍橋杯(3.3)

1208. 翻硬幣 import java.util.Scanner;public class Main {public static void turn(char[] a,int i) {if(a[i] *) a[i] o;else a[i] *;}public static void main(String[] args) {Scanner sc new Scanner(System.in);char[] a sc.next().toCharArray();char[] b sc.n…

python如何設置虛擬環境|方法有哪幾種

原文連接&#xff1a; python設置虛擬環境- Python學習導航 為什么需要虛擬環境&#xff1f; 在使用Python語言時&#xff0c;通過pip&#xff08;pip3&#xff09;來安裝第三方包&#xff0c;但是由于pip的特性&#xff0c;系統中只能安裝每個包的一個版本。但是在實際項目開…