How do I make a progress bar for loading pandas DataFrame from a large xlsx file?

The following is a one-liner solution utilizing tqdm: import pandas as pd from tqdm import tqdm df = pd.concat([chunk for chunk in tqdm(pd.read_csv(file_name, chunksize=1000), desc=”Loading data”)]) If you know the total lines to be loaded, you can add that information with the parameter total to the tqdm fuction, resulting in a percentage output.

tqdm not showing bar

tqdm needs to known how many iters will be performed (the total amount) to show a progress bar. You can try this: from tqdm import tqdm train_x = range(100) train_y = range(200) train_iter = zip(train_x, train_y) # Notice `train_iter` can only be iter over once, so i get `total` in this way. total = min(len(train_x), … Read more

Change logging “print” function to “tqdm.write” so logging doesn’t interfere with progress bars

tqdm now has a built-in contextmanager for redirecting the logger: import logging from tqdm import trange from tqdm.contrib.logging import logging_redirect_tqdm LOG = logging.getLogger(__name__) if __name__ == ‘__main__’: logging.basicConfig(level=logging.INFO) with logging_redirect_tqdm(): for i in trange(9): if i == 4: LOG.info(“console logging redirected to `tqdm.write()`”) # logging restored Copied from tqdm documentation

Using multiple bars

Try using the position parameter when initialising the bars: pbar1 = tqdm(total=100, position=1) pbar2 = tqdm(total=200, position=0) From the tqdm GitHub page: position : int, optional Specify the line offset to print this bar (starting from 0) Automatic if unspecified. Useful to manage multiple bars at once (eg, from threads).

Starmap combined with tqdm?

The simplest way would probably be to apply tqdm() around the inputs, rather than the mapping function. For example: inputs = zip(param1, param2, param3) with mp.Pool(8) as pool: results = pool.starmap(my_function, tqdm.tqdm(inputs, total=len(param1))) Note that the bar is updated when my_function is called, rather than when it returns. If that distinction matters, you can consider … Read more