Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a tqdm progress_apply bar in vscode + python jupyter extension?

I am trying to display a progress bar when I perform "vector" progress_apply operations on pandas dataframes, in MS Visual Studio Code.

In VS Code with the Python extension enabled, I tried in a cell

import pandas as pd 
from tqdm import tqdm_notebook, tqdm_pandas 

tqdm_notebook().pandas()

df = pd.DataFrame({'a' : ['foo', 'bar'], 'b' : ['spam', 'eggs']}) 
df.progress_apply(lambda row: row['a'] + row['b'], axis = 1)

And the result is not OK (edit: this may actually render fine on more recent versions of VS Code).

progress bar render fails with vscode

How can I visualize the progress bar when I run pandas progress_apply in vscode?

like image 591
Davide Fiocco Avatar asked Jan 28 '20 16:01

Davide Fiocco


People also ask

Does tqdm work in Jupyter notebook?

TQDM is a progress bar library with good support for nested loops and Jupyter/IPython notebooks.

How do I download tqdm in Python?

Type "cmd" in the search bar and hit Enter to open the command line. What is this? Type “ pip install tqdm ” (without quotes) in the command line and hit Enter again. This installs tqdm for your default Python installation.

Where do you put tqdm?

Usage. Using tqdm is very simple, you just need to add your code between tqdm() after importing the library in your code. You need to make sure that the code you put in between the tqdm() function must be iterable or it would not work at all.


1 Answers

Revisiting this in 2022 (VS Code 1.63.2), the code below will work fine in VS code, and may be more appealing visually than the other solution I previously had for this:

import pandas as pd 
from tqdm.notebook import tqdm

tqdm.pandas()

df = pd.DataFrame({'a' : ['foo', 'bar'], 'b' : ['spam', 'eggs']}) 
df.progress_apply(lambda row: row['a'] + row['b'], axis = 1)

VS code tqdm bar render

like image 66
Davide Fiocco Avatar answered Nov 04 '22 15:11

Davide Fiocco