<p>由于流行的需求,<code>tqdm</code>增加了对<code>pandas</code>的支持。与其他答案不同,这个<strong>不会明显减慢熊猫的速度</strong>--下面是一个<code>DataFrameGroupBy.progress_apply</code>的示例:</p>
<pre><code>import pandas as pd
import numpy as np
from tqdm import tqdm
# from tqdm.auto import tqdm # for notebooks
df = pd.DataFrame(np.random.randint(0, int(1e8), (10000, 1000)))
# Create and register a new `tqdm` instance with `pandas`
# (can use tqdm_gui, optional kwargs, etc.)
tqdm.pandas()
# Now you can use `progress_apply` instead of `apply`
df.groupby(0).progress_apply(lambda x: x**2)
</code></pre>
<p>如果您对它的工作方式感兴趣(以及如何为自己的回调修改它),请参见<a href="https://github.com/tqdm/tqdm/tree/master/examples" rel="noreferrer">examples on github</a>、<a href="https://pypi.python.org/pypi/tqdm" rel="noreferrer">full documentation on pypi</a>,或者导入模块并运行<code>help(tqdm)</code>。</p>
<p><strong>编辑</strong></p>
<hr/>
<p>要直接回答原始问题,请替换:</p>
<pre><code>df_users.groupby(['userID', 'requestDate']).apply(feature_rollup)
</code></pre>
<p>使用:</p>
<pre><code>from tqdm import tqdm
tqdm.pandas()
df_users.groupby(['userID', 'requestDate']).progress_apply(feature_rollup)
</code></pre>
<p><strong>注意:tqdm<;=v4.8</strong>:
对于低于4.8的TQM版本,您必须执行以下操作,而不是<code>tqdm.pandas()</code>:</p>
<pre><code>from tqdm import tqdm, tqdm_pandas
tqdm_pandas(tqdm())
</code></pre>