python-3.x - 进度条随列表长度更新
问题描述
我正在使用 tqdm 作为进度条。这是示例代码
from tqdm import tqdm
import numpy as np
import pandas as pd
for index_len in tqdm(range(0,len(data_elim))):
# Doing something here where i get a array of rows which i need to delete
data_elim = np.delete(data_elim.values,same_residues,0
data_elim = pd.DataFrame(data_elim)
所以在这种情况下,我的初始长度是 17 百万,但随着它的进一步发展,它会减少并最终归零。但在我的进度条中,它始终显示为列表的初始长度。无论如何我也可以在进度栏中更改该数字吗?
解决方案
在不运行代码的情况下,感觉就像您可以重写它以使用tqdm
“手动”模式更明确:
total_count = len(data_elim)
with tqdm(total=total_count) as progress:
# ... do stuff, yielding `new_data`; or, calculate rows_deleted differently
rows_deleted = total_count - len(new_data)
progress.update(rows_deleted)
推荐阅读
- python - 如何在python 3中生成随机浮点数
- oracle-apex - 如何通过使用 BI Publisher 在 APEX 中传递参数来打印单个查询
- javascript - highlight.js 的自定义语言定义
- c - 使用 sem_t 时大小为 8 的无效写入
- angular - 如何在 ftl 文件中获取当前页面 url
- javascript - Angular 模板未在 RxJS 可观察更改上更新
- api - 无法连接到服务器端 API
- android - Android Studio 4.2 在我尝试打开它时没有响应
- python - 为什么在这个例子中没有提出未定义的 NameError?
- angular - 同一客户端的不同重定向 uri - Keycloak + Angular + SpringBoot