【发布时间】:2019-10-08 22:39:59
【问题描述】:
我可以找到用于 group by 和其他 pandas 操作的 tqdm 进度条的示例。但在合并或加入时找不到任何东西。
是否可以在 pandas 上使用 tqdm 进行合并?
【问题讨论】:
-
@johny Mudly 我已经看到了这个问题。在任何答案中都没有熊猫合并/加入操作的示例。
我可以找到用于 group by 和其他 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)
【讨论】: