pythonpandasvisual-studio-codejupyter-notebooktqdm

How can I get a tqdm progress_apply bar in pandas operations 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

  • 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