def csv_to_rows(input):
reader = get_csv_reader(input)
rows = [d for d in reader]
fields = reader.fieldnames
output = {'fields': fields, 'rows': rows}
# Attempt numeric conversion
for row in output['rows']:
for col in row:
try:
row[col] = int(row[col])
except Exception:
try:
orig = row[col]
row[col] = float(row[col])
# Disallow NaN, Inf, -Inf since this does not
# pass through JSON converters cleanly
if math.isnan(row[col]) or math.isinf(row[col]):
row[col] = orig
except Exception:
pass
return output
评论列表
文章目录