How to use tqdm with pandas in a jupyter notebook? How to use tqdm with pandas in a jupyter notebook? python python

How to use tqdm with pandas in a jupyter notebook?


My working solution (copied from the documentation):

from tqdm.auto import tqdmtqdm.pandas()


You can use:

tqdm_notebook().pandas(*args, **kwargs)

This is because tqdm_notebook has a delayer adapter, so it's necessary to instanciate it before accessing its methods (including class methods).

In the future (>v5.1), you should be able to use a more uniform API:

tqdm_pandas(tqdm_notebook, *args, **kwargs)


I found that I had to import tqdm_notebook also. A simple example is given below that works in Jupyter notebook.

Given you want to map a function on a variable to create a new variable in your pandas dataframe.

# progress barfrom tqdm import tqdm, tqdm_notebook# instantiatetqdm.pandas(tqdm_notebook)# replace map with progress_map# where df is a pandas dataframedf['new_variable'] = df['old_variable'].progress_map(some_function)