Skip to content

Instantly share code, notes, and snippets.

@izikeros
Last active March 15, 2024 19:59
Show Gist options
  • Save izikeros/87d4cb79d92036f00b57c77739c30b06 to your computer and use it in GitHub Desktop.
Save izikeros/87d4cb79d92036f00b57c77739c30b06 to your computer and use it in GitHub Desktop.
[DataFrame processing progress bar] Display progress bar while processing pandas dataframe #pandas
# from:
# https://stackoverflow.com/a/34365537/3247880
# see internals:
# https://github.com/tqdm/tqdm/blob/master/examples/pandas_progress_apply.py
import pandas as pd
import numpy as np
from tqdm import tqdm
# from tqdm.auto import tqdm # for notebooks
df = pd.DataFrame(np.random.randint(0, int(1e8), (10000, 1000)))
# Create and register a new `tqdm` instance with `pandas`
# (can use tqdm_gui, optional kwargs, etc.)
tqdm.pandas()
# Now you can use `progress_apply` instead of `apply`
df.groupby(0).progress_apply(lambda x: x**2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment