Last active
December 17, 2015 11:39
-
-
Save danabauer/5603439 to your computer and use it in GitHub Desktop.
Quick script to convert dbf for csv. Tested with large 2010 census block data
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
""" | |
--------------------------------------------------------------------------- | |
dbf_to_csv.py | |
Dana Bauer | |
Feb 1, 2012 | |
--------------------------------------------------------------------------- | |
""" | |
import csv | |
from dbfpy import dbf | |
try: | |
dbfFile = dbf.Dbf(open(r'c:\projects\MN\MN_block_name.dbf','r')) | |
csvFile = csv.writer(open(r'c:\projects\MN\MNblocks.csv', 'wb')) | |
headers = range(len(dbfFile.fieldNames)) | |
allRows = [] | |
for row in dbfFile: | |
rows = [] | |
for num in headers: | |
rows.append(row[num]) | |
allRows.append(rows) | |
csvFile.writerow(dbfFile.fieldNames) | |
for row in allRows: | |
print row | |
csvFile.writerow(row) | |
except Exception,e: | |
print e | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment