Created
April 9, 2011 18:02
-
-
Save zstumgoren/911615 to your computer and use it in GitHub Desktop.
Sample script on how to use Python's csv DictReader class to process tabular 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
#!/usr/bin/env python | |
import csv | |
source_file = open('/path/to/Testfile.txt','rb') | |
# Use the DictReader class to read in your data. This class allows you to access | |
# field names by name. It assumes the first line in the file contains the field names | |
for line in csv.DictReader(source_file, delimiter='\t'): | |
net_income = line['net_income'].strip().replace('(','-').replace(')','') | |
bank_name = line['name'].strip() | |
# process other fields as necessary, and then print them to shell | |
print bank_name, net_income |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment