Home > OS >  pandas read_csv method busy status
pandas read_csv method busy status

Time:10-09

I am trying to implement a "busy" status indicator when using Python Pandas read_csv method to upload data from csv files. This is particularly useful when uploading large csv files that keep the terminal busy until data is loaded into the memory. However, I can't get any simple solution to work with Pandas. A simple cursor indicator such as this one that I use would be very useful if it can be integrated in the read_csv method.

import itertools
import sys

busy = itertools.cycle([' \ ', ' / '])
sys.stdout.write(next(busy))
sys.stdout.flush()
sys.stdout.write('\b\b\b')

Any suggestions on implementing such a solution for the read_csv method in pandas?

CodePudding user response:

You could use some kind of "monitor" thread. Something like this:

import itertools
from threading import Thread
import time
import sys

BUSY = True

def busy():
    b = itertools.cycle([' \ ', ' / '])
    while BUSY:
        sys.stdout.write(next(b))
        sys.stdout.flush()
        sys.stdout.write('\b\b\b')
        time.sleep(0.2)

t = Thread(target=busy)
t.start()
# sleep here emulates your time-consuming operation
time.sleep(5)

BUSY = False
t.join()

Your could also consider using events. I offer this only as a very simplistic approach

  • Related