【问题标题】:Is it possible to use tqdm for pandas merge operation? [duplicate]是否可以使用 tqdm 进行 pandas 合并操作? [复制]
【发布时间】:2019-10-08 22:39:59
【问题描述】:

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

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

【问题讨论】:

  • @johny Mudly 我已经看到了这个问题。在任何答案中都没有熊猫合并/加入操作的示例。

标签: python pandas tqdm


【解决方案1】:

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)

【讨论】:

  • 我认为,它只是显示了apply函数的进度,而不是实际的合并操作。
  • 这里描述了我发现的唯一可能的方法(它使用 Dask 作为解决方法):stackoverflow.com/a/68936833/3921758
猜你喜欢
  • 2015-01-03
  • 1970-01-01
  • 2012-04-14
  • 2010-11-25
  • 2023-03-21
相关资源
最近更新 更多