How to Add a Progress Bar into Pandas Apply

56

import pandas as pd
from tqdm import tqdm

# Create new `pandas` methods which use `tqdm` progress
# (can use tqdm_gui, optional kwargs, etc.)
tqdm.pandas()

# Now you can use `progress_apply` instead of `apply`
df.progress_apply(lambda x: x**2)
If you are applying any function on pandas dataframe column and want to track the progress
you can use the following command

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

# instead of apply use `progress_apply`
df['col'].progress_apply(lambda x: x**2)

## If you get any error like `ImportError: IProgress not found` then you can install/update your
jupyter and Ipywidgets packages using following command
1. pip install ipywidgets==7.4.2

Comments

Submit
0 Comments