mercredi 10 mars 2021

Python generator to lazy read large csv files and shuffle the rows

I will like to write a function that yields shuffled rows of a large csv file. How can that be done?

def readCSV(csvname, shuffle=True):

    if shuffle:
        # Do something to shuffle the order of the rows
        # But I dont' know how to do this.

    for row in open(csvname, "r"):
        yield row




Aucun commentaire:

Enregistrer un commentaire