pandas添加进度条

首先需要导包与声明:

from tqdm import tqdm
tqdm.pandas(desc='pandas bar')

然后在使用的时候,用新函数替换掉原本的函数(并不会影响内在逻辑):

原本的函数 新函数
apply progress_apply

更多用法请参考:https://github.com/tqdm/tqdm/tree/master/examples

使用示例

from tqdm import tqdm
import pandas as pd
import numpy as np

tqdm.pandas(desc='pandas bar')


def check_apple(value):
    import time
    time.sleep(1)


if __name__ == '__main__':
    series = pd.Series(np.random.randint(0, 10, size=100))
    series.progress_apply(check_apple)

猜你喜欢

转载自blog.csdn.net/weixin_35757704/article/details/121835329