Created
February 25, 2014 09:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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