I would like to find the Max length for each column in a tab delimited csv file. I can find the max value of one column by using this:
import csv
oldlen=0
with open(mfile) as csvfile:
test = csv.reader(csvfile,dialect='excel-tab')
for row in test:
if len(row[0]) > oldlen:
newlen = len(row[0])
print (newlen)
If I wish to do all columns (and count them), I could just change row[] manually, but I wish to learn so I tried this:
with open(mfile) as csvfile:
test = csv.reader(csvfile,dialect='excel-tab')
ncol=len(test[0])
for column in test:
for row in test:
if len(row[column]) > oldlen:
newlen = len(row[0])
print (column,newlen)
Which, of course, doesnt make programatic sense. But it indicates, I hope, what my intention is. I have to do the columns first so I can get the max length out of each column, across all rows.