【问题标题】:Progress bar update with the length of the list进度条随列表长度更新
【发布时间】:2021-08-05 10:46:43
【问题描述】:

我正在使用 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 百万,但随着它的进一步发展,它会减少并最终归零。但在我的进度条中,它始终显示为列表的初始长度。无论如何我也可以在进度栏中更改该数字吗?

【问题讨论】:

  • 您是否将代码用于较小的数据集?如果您的总行数为 17M,则在删除 170K 行后,进度条的 1% 将发生变化(假设进度条每 1% 更新一次)。也许没有足够的时间发生这种情况?

标签: python-3.x progress-bar tqdm


【解决方案1】:

不运行代码,感觉就像你可以重写它以使用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)

【讨论】:

    猜你喜欢
    • 2012-05-22
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多