There's are a few questions regarding this but I can't seem to find one that executes a progress bar on a non-iterable function. Below is a function that merges two separate data frames. I'm hoping to insert this function into a separate one that display the progress.
from multiprocessing import Pool
import tqdm
import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.randint(0,100,size=(100000, 4)), columns=list('ABCD'))
df2 = pd.DataFrame(np.random.randint(0,100,size=(100000, 4)), columns=list('AXYZ'))
def merge_df(df1, df2):
df = pd.merge(left = df1, right = df2, how = 'left',
left_on = 'A', right_on = 'A')
return df
if __name__ == '__main__':
with Pool(2) as p:
r = list(tqdm.tqdm(p.imap(merge_df, df1, df2)))
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().