【问题标题】:How to add a description to tqdm pandas?如何向 tqdm pandas 添加描述?
【发布时间】:2020-09-14 12:18:06
【问题描述】:

我想在 tqdm pandas 进度条之前(或之后,并不重要)放一个小描述,如下所示:

import numpy as np
import pandas as pd
from tqdm.auto import tqdm; tqdm.pandas()

a = pd.Series(np.arange(100))

squares = a.progress_map(lambda x: x**2) #this one works
cubes = a.progress_map(lambda x: x**3) #this one works

squares = a.progress_map(lambda x: x**2, desc = 'Computing squares...') #this one doesn't work
cubes = a.progress_map(lambda x: x**3, desc = 'Computing cubes...') #this one doesn't work

那么,如何在进度条中添加描述?

【问题讨论】:

    标签: python pandas tqdm


    【解决方案1】:

    也许是这样的:

    import numpy as np
    import pandas as pd
    from tqdm.auto import tqdm
    
    a = pd.Series(np.arange(100))
    
    tqdm.pandas(desc='Computing squares')
    squares = a.progress_map(lambda x: x**2)
    
    tqdm.pandas(desc='Computing cubes')
    cubes = a.progress_map(lambda x: x**3)
    

    输出:

    Computing squares: 100%|██████████| 100/100 [00:00<00:00, 37766.11it/s]
    Computing cubes: 100%|██████████| 100/100 [00:00<00:00, 30211.80it/s]
    

    【讨论】:

      【解决方案2】:

      这会起作用,但您会收到警告:

      squares = a.progress_map(lambda x: x**2,print('Computing squares...') ) 
      

      【讨论】:

        猜你喜欢
        • 2016-04-14
        • 2021-10-06
        • 1970-01-01
        • 2012-01-31
        • 1970-01-01
        • 1970-01-01
        • 2013-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多