def read_and_wrangle(src, dest):
wf = dest.open('w')
wcsv = csv.DictWriter(wf, fieldnames=FINAL_HEADERS)
wcsv.writeheader()
# only 2011.csv has windows-1252 instead of ascii encoding,
# but we open all files as windows-1252 just to be safe
with src.open("r", encoding='windows-1252') as rf:
records = csv.DictReader(rf)
for i, row in enumerate(records):
row = strip_record(row)
newrow = wrangle_record(row)
wcsv.writerow(newrow)
# a little status checker
if i % 10000 == 1:
print("...wrote row #", i)
# done writing file
print("Wrangled", i, "rows and saved to", dest)
wf.close()
wrangle_nypd_stop_and_frisk_data.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录