Skip to content

Instantly share code, notes, and snippets.

@NelsonMinar
Created January 10, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NelsonMinar/f67a5900c9e81d2c111d to your computer and use it in GitHub Desktop.
Save NelsonMinar/f67a5900c9e81d2c111d to your computer and use it in GitHub Desktop.
Quickie script to check an OpenAddresses source CSV file for a consistent number of rows
#!/usr/bin/env python3
"""Check a CSV source for consistent number of rows
Usage: checkCsv.py encoding filename"""
import sys
counts = {}
fp = open(sys.argv[2], encoding=sys.argv[1])
for l in fp:
n = len(l.split(','))
counts[n] = counts.get(n, 0) + 1
if len(counts.keys()) == 1:
print("All rows in file have %s columns" % list(counts.keys())[0])
else:
print("Rows have an inconsistent number of columns")
for k in sorted(list(counts.keys())):
print(" %3d %7d" % (k, counts[k]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment