Created
November 18, 2014 13:51
-
-
Save qoda/6a35cd850c5c6b1b926b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import csv | |
import sys | |
def fix_case(name): | |
splitname = name.split() | |
return " ".join([n.lower().capitalize() for n in splitname]) | |
def extract(file_path): | |
originalcsv = csv.DictReader(open(file_path, 'r')) | |
newcsv = csv.writer(open("output.csv", 'w')) | |
newcsv.writerow(['MSISDN', 'First Name', 'Last Name']) | |
for line in originalcsv: | |
splitname = line['S_NAME_CUS'].split() | |
firstname, lastname = splitname[0], splitname[-1] if len(splitname) > 1 else "" | |
newcsv.writerow( | |
[line['MSISDN_CURR'], fix_case(firstname), fix_case(lastname)] | |
) | |
if __name__ == '__main__': | |
extract(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment