如何让 tqdm 在 pandas 应用上工作?
Tqdm 文档显示了 tqdm 使用 Progress_apply 处理 pandas apply 的示例。我从这里改编了以下代码 https://tqdm.github.io/docs/tqdm/ 通常需要几分钟才能执行的进程(func1 是正则表达式函数)。
from tqdm import tqdm
tqdm.pandas()
df.progress_apply(lambda x: func1(x.textbody), axis=1)
生成的进度条不显示任何进度。它只是从循环开始时的 0 跳到循环结束时的 100。我当前正在运行 tqdm 版本 4.61.2
Tqdm documentation shows an example of tqdm working on pandas apply using progress_apply. I adapted the following code from here https://tqdm.github.io/docs/tqdm/ on a process that regularly take several minutes to perform (func1 is a regex function).
from tqdm import tqdm
tqdm.pandas()
df.progress_apply(lambda x: func1(x.textbody), axis=1)
The resulting progress bar doesn't show any progress. It just jumps from 0 at the start of the loop to 100 when it is finished. I am currently running tqdm version 4.61.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 tqdm 与 pandas 结合使用
一般来说,人们在对列或行执行操作时倾向于使用 lambda。这可以通过多种方式来完成。
示例 1:
输出:
输出
示例 2:
Utilizing tqdm with pandas
Generally speaking, people tend to use lambdas when performing operations on a column or row. This can be done in a number of ways.
Example 1:
Output:
Output
Example 2: