对于pandas函数在运行的过程中,如果数值的数量过多,此时一些pandas自带的函数,比如merge,concat等函数,往往会由于运行时间过长,导致你不知道它会运行到哪里,会运行多长时间,此时我们选择自己写循环加进度条来解决这一问题
from tqdm import tqdm
import pandas as pd
import numpy as np
df1 = pd.DataFrame({"A":[1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0],
"B":[1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0],
"C":[1.0, 1.5, 2.0, 2.0, 3.0, 4.0, 5.0, 6.0, 10.0],
"D":[2.0, 5.0, 3.0, 6.0, 4.0, 2.0, 5.0, 1.0, 2.0],
"E":['a', 'a', 'b', 'a', 'b', 'b', 'b', 'a', 'a']})
df2 = pd.DataFrame({"A":[1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0],
"G":[1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0],
"K":[1.0, 1.5, 2.0, 2.0, 3.0, 4.0, 5.0, 6.0, 10.0]})
df = df1.merge(df2,how="inner",on="A")
df.head()
for index, row in tqdm(df.iterrows(),total=len(df)):
#需要调用的操作
当然这种写法肯定要比pandas自带的写法耗时要长,如果有时间的话,可以研究一下pandas之中自带的函数运行过程