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).
How can I visualize the progress bar when I run pandas progress_apply
in vscode?
TQDM is a progress bar library with good support for nested loops and Jupyter/IPython notebooks.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With