I have a CSV file, titled jobData with this data:
EMPLOYEE,START_DATE,END_DATE,JOB,DIVISION
Tom 20180101 20191028 Job1 Div_B
Tom 20160101 20171231 Job1 Div_B
Tom 20150609 20151231 Job1 Div_B
Dick 20191001 Job4 Div_D
Dick 20190609 20190930 Job3 Div_C
Dick 20170309 20180608 Job2 Div_A
Dick 20160609 20170308 Job1 Div_B
Harry 20180701 Job2 Div_A
Harry 20180101 20180630 Job2 Div_A
Harry 20160101 20171231 Job1 Div_A
My objective is to structure the data in a dictionary so that each employee is the key, and the value is a list of jobs in chronological order
For example: d = { Tom : [Job1], Dick : [Job1, Job2, Job3, Job4], Harry : [Job1, Job2]}
Currently I have this script:
import csv
jobDataFile = open('jobData.csv')
jobDataReader = csv.reader(jobDataFile)
jobData = list(jobDataReader)
dict = {}
for row in jobData:
if row[0] not in dict.keys():
dict[row[0]] = []
else:
if row[3] not in dict[row[0]]:
dict[row[0]].append(row[3])
At this point I get a dictionary, with employee as the key, and a list of job as the value, but the list items are not in chronological order.
How do I use the information in 'startdate' to order the list in each value?