如何在tqdm pandas中添加描述?

4
我希望在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

那么,我该如何添加进度条的描述呢?

2个回答

2
也许是这样的:
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)

Output:

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

0

这个会起作用,但是你会收到一个警告:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接