如何向 tqdm pandas 添加描述?

How to add a description to tqdm pandas?

我想在 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

那么,如何给进度条添加描述呢?

这可行,但您会收到警告:

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

也许是这样:

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]