Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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? :)

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!")
  

notebook support is still in a (late) beta stage. The API might change slightly when we release tqdm v5 but for now you probably need

from tqdm._tqdm_notebook import tqdm_notebook
tqdm_notebook.pandas(...

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

Assuming your question is about how to use the status bar, vs the ascetics of the status bar on the Jupyter NoteBook then your code should be

tqdm.pandas(desc="Example Desc")
keywords_df['keyword'] = keywords_df['keywird'].progress_apply(lambda x: x.replace('*',''))
                Ascetics quite important, because it's the main reason to use tqdm_notebook (not just tqdm). Also, tqdm_notebook works with nested bars, while static tqdm has some issues with colorama :)
– sortas
                Aug 9, 2017 at 20:54
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.