M
tqdm用法非常简单,只需在平常循环的对象上套上tqdm函数,就可以看到运行进度啦!
from tqdm import tqdm
for i in tqdm(range(100)):
i = i * 2
如果你用的是Jupyter notebook,建议用这个notebook.tqdm函数,或者auto.tqdm
from tqdm.notebook import tqdm
# from tqdm.auto import tqdm
for i in tqdm(range(100)):
i = i * 2
这个函数画出的Progress Bar更好看
如果你用的是Pandas apply,也可以用tqdm包显示运行进度哦
代码来源:https://stackoverflow.com/questions/18603270/progress-indicator-during-pandas-operations
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)