DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Andrew has posted 6 posts at DZone. View Full User Profile

Merging Cells

09.10.2009
| 4008 views |
  • submit to reddit
        // This code reads a CSV file, takes two fields and merges them, then writes the merged field to a text file.

import csv
import os

os.chdir('Desktop')
cwd = os.getcwd()

reader = csv.reader(open('september crime data.csv', 'r'), dialect='excel')
open_file = open('streets.txt', 'w')

for row in reader:
    street_number = row[9]
    street_name = row[3]

    open_file.write(street_number + ' ' + street_name + '\n')
    

open_file.close()