Current location - Loan Platform Complete Network - Big data management - How does Python read the column names and corresponding data in CVS file in turn?
How does Python read the column names and corresponding data in CVS file in turn?
Import csv doesn't seem to provide a method of reading by column. Define a temporary use like this.

Import csv

Def colreader (file name, * parameter, *kwarg):

Use open (file name,' r') as f:

reader = csv.reader(f,*arg,**kwarg)

Length = 0

For rows in the reader:

Length = length (line)

break

Reader = List (Reader)

For I (length) in the range:

Result = [x[i] for x in reader]

Yield result

Restricted by level. The reader in csv module is similar to a generator, and the iteration encounters some problems, so it is simply and rudely regarded as a list. When encountering a large amount of data, it will crash, so it can only be used temporarily, and the formal use needs to be improved.