是否可以使用 tqdm 进行 pandas 合并操作?

Is it possible to use tqdm for pandas merge operation?

我可以找到用于分组依据和其他 pandas 操作的 tqdm 进度条示例。但在合并或加入时找不到任何内容。

是否可以在 pandas 上使用 tqdm 进行合并?

tqdm 支持 pandas 和其中的各种操作。要合并两个大数据框并显示进度,您可以这样做:

import pandas as pd
from tqdm import tqdm

df1 = pd.DataFrame({'lkey': 1000*['a', 'b', 'c', 'd'],'lvalue': np.random.randint(0,int(1e8),4000)})
df2 = pd.DataFrame({'rkey': 1000*['a', 'b', 'c', 'd'],'rvalue': np.random.randint(0, int(1e8),4000)})

#this is how you activate the pandas features in tqdm
tqdm.pandas()
#call the progress_apply feature with a dummy lambda 
df1.merge(df2, left_on='lkey', right_on='rkey').progress_apply(lambda x: x)

此线程提供了更多详细信息: Progress indicator during pandas operations (python)