728x90
1. tqdm in list comprehension / in pandas
import pandas as pd
import numpy as np
from tqdm import tqdm
# from tqdm.notebook import tqdm # Ver. 1 For Jupyter Notebook
# from tqdm.auto import tqdm # Ver. 2 For Jupyter Notebook
def process(token):
return token['text']
l1 = [{'text': k} for k in range(5000)]
l2 = [process(token) for token in tqdm(l1)] # tqdm in list comprehension
#--------------------------------------------------------------#
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)
728x90