Skip to content

Instantly share code, notes, and snippets.

@schwuk
Created February 25, 2014 09:05
Show Gist options
  • Save schwuk/9205425 to your computer and use it in GitHub Desktop.
Save schwuk/9205425 to your computer and use it in GitHub Desktop.
A quick'n'dirty script to describe a CSV file - outputs the header for each column and the maximum width of that column.
#! /usr/bin/env python
import csv
import sys
with open(sys.argv[1], 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
header = reader.next()
columns = []
for row in reader:
for i, v in enumerate(row):
_length = len(v)
try:
if _length > columns[i]:
columns[i] = _length
except IndexError:
columns.append(_length)
for i, v in enumerate(header):
print '%s %i' % (v, columns[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment