'How can I get a tqdm progress_apply bar in VS Code notebooks?

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?



Solution 1:[1]

This version worked fine on my version of vscode and python extension:

import pandas as pd
from tqdm import tqdm
tqdm.pandas()

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

Fix

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1