Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix tqdm progress_apply for pandas in Jupyter?

Tags:

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!") 
like image 221
sortas Avatar asked Aug 09 '17 16:08

sortas


People also ask

Does tqdm work in Jupyter notebook?

tqdm works on any platform (Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS), in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.

What is tqdm () in Python?

You just need to wrap tqdm on any iterable - tqdm(iterable). tqdm can help you create progress bars for data processing, training machine learning models, multi-loop Python function, and downloading data from the internet. Install the package using pip: pip install tqdm.

What is Progress_apply?

The progress_apply() method is part of the originally created tqdm package which enables you to create a progress meter and estimate “Time To Completion” for your iterations.


2 Answers

Now you can just do:

from tqdm.notebook import tqdm tqdm.pandas()  df.progress_apply(...) 

My version of tqdm is 4.39.0

like image 156
Onno Eberhard Avatar answered Sep 29 '22 23:09

Onno Eberhard


Answer from tqdm developer:

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(... 
like image 29
sortas Avatar answered Sep 29 '22 22:09

sortas