是否可以将 tqdm 用于 Pandas 合并操作?

rah*_*hul 2 python pandas tqdm

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

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

HMR*_*ble 7

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)
Run Code Online (Sandbox Code Playgroud)

此线程上提供了更多详细信息: pandas 操作期间的进度指示器 (python)

  • 我认为,它只是显示了 apply 函数的进度,而不是实际的合并操作。 (2认同)