如何在tqdm熊猫中添加描述?

问题描述

我想在tqdm熊猫进度条的前面(或后面,没什么关系)做一个简短的描述,如下所示:

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

那么,如何在进度条上添加说明?

解决方法

也许是这样

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]
,

这将起作用,但是您会得到警告:

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