How to fix tqdm progress_apply for pandas in Jupyter?

Viewed 41593

Don't really understand is it a mistake or just my local problem, still have some issues with using tqdm progress bars with progress_apply in Jupyter.

First try:

from tqdm import tqdm
tqdm_notebook.pandas(desc="Example Desc")
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))

Output (without any bars):

AttributeError: 'function' object has no attribute 'pandas'

Second try:

from tqdm import tqdm
tqdm_notebook().pandas(desc="Example Desc")
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))

Output: Two bars (need one). First bar is empty (0it [00:00, ?it/s]), second is OK.

Any ideas how to change progress_apply description and display bar without empty initialization bar? :)

P.S. Documentation (https://github.com/tqdm/tqdm) says I can just use tqdm_notebook, but it's not working for me :)

# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
# (can use `tqdm_gui`, `tqdm_notebook`, optional kwargs, etc.)
tqdm.pandas(desc="my bar!")
5 Answers

Now you can just do:

from tqdm.notebook import tqdm
tqdm.pandas()

df.progress_apply(...)

My version of tqdm is 4.39.0

This is what I run in my jupyter notebooks, and then progress_apply works:

from tqdm import tqdm, tqdm_notebook
tqdm_notebook().pandas()

I had been getting an error without the () after tqdm_notebook

The following is working for me:

from tqdm import tqdm
tqdm.pandas()
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))
Related