Im very very new to python, I’m using it here as Im told it’s good for fileIO.
I have a CSV file in the following format. It records the daily activity for my staff.
Date, Name, Project, Manager
01/01/10, Tommy, HyperDyne, Joe Bloggs
01/01/10, Sue, Robot, Joe Bloggs
01/01/10, Mark, HyperDyne, Joe Bloggs
02/01/10, Tommy, SICK,
03/01/10, Tommy, HyperDyne, Joe Bloggs
When an employee is marked as SICK, the manager field is always blank. I want to fill in the Manager field with the previous manager entry for that employee. I want to fill in all the blanks in the csv, and put in NULLS when we cannot say.
In pseudocode-ish:
Forall lines n
if n.Project = "Sick"
y = 1
if n-y.name = n.name
n.manager = n-y.manager
else y++
if y > n
n.manager = null
(could probably wrap that into a for y < n loop perhaps)
This would need to be either edit the input file, or output a new file. I suspect editing the input file would be easier, as people can be sick multiple days in a row.
Would love some advice, its been ages since Ive done procedural programming
You could go through each line of input.csv, read + check it and then write it to output csv.
While you loop through the lines, keep a record of the previous manager for each person.
When you encounter a ‘SICK’ row, lookup the previous manager in your records
Here’s some incpomplete code to illustrate: