From 88b395396e8db671642eb5101693f5674fca9226 Mon Sep 17 00:00:00 2001 From: Salton Date: Mon, 2 Nov 2015 09:24:59 +0000 Subject: [PATCH] [ADD] initial commit of script --- convert_old_alw_to_new_structure.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 convert_old_alw_to_new_structure.py diff --git a/convert_old_alw_to_new_structure.py b/convert_old_alw_to_new_structure.py new file mode 100644 index 0000000..da6ea7b --- /dev/null +++ b/convert_old_alw_to_new_structure.py @@ -0,0 +1,26 @@ +import csv +#csv file from which the original data is read +with open('hr.contract (8).csv') as csvfile1: + #csv file to which new data is written + with open('csvfile.csv','w') as csvfile2: + #the keys in the new csv file + fieldnames = ['External ID', 'Allowances', 'Allowances/Amount'] + #the row values in the old csv file are assigned to "reader" + reader = csv.DictReader(csvfile1) + #write the headers in the new csv file + writer = csv.DictWriter(csvfile2,fieldnames=fieldnames) + writer.writeheader() + #main data conversion + for row in reader: + writer.writerow({'External ID': row['External ID'], + 'Allowances': '__export__.hr_payroll_allowance_line_1', + 'Allowances/Amount': row['Medical']}) + writer.writerow({'External ID': '', + 'Allowances': '__export__.hr_payroll_allowance_line_2', + 'Allowances/Amount': row['Transport']}) + writer.writerow({'External ID': '', + 'Allowances': '__export__.hr_payroll_allowance_line_3', + 'Allowances/Amount': row['Rent']}) + + +