I have the following dataframe that shows the duration of a job taken by an employee as shown:
| Date | ID number | Hour | Job duration |
|---|---|---|---|
| 14/07/2022 | 1123 | 12 | 240 |
| 14/07/2022 | 1123 | 13 | 0 |
| 14/07/2022 | 1123 | 14 | 0 |
| 14/07/2022 | 1123 | 15 | 0 |
| 14/07/2022 | 1123 | 16 | 70 |
| 14/07/2022 | 1123 | 17 | 0 |
I've iterated through the dataframe to "spread" the minutes along the hour using the following code:
for i in df.index:
if df["Job duration"][i] > 60:
x = df["Job duration"][i] - 60
df["Job duration"][i] = 60
df["Job duration"][i+1] = df["Job duration"][i+1] + x
This code works in a small dataset as shown below. In a large dataset however, this doesn't work and will take a long time computationally.
| Date | ID number | Hour | Job duration |
|---|---|---|---|
| 14/07/2022 | 1123 | 12 | 60 |
| 14/07/2022 | 1123 | 13 | 60 |
| 14/07/2022 | 1123 | 14 | 60 |
| 14/07/2022 | 1123 | 15 | 60 |
| 14/07/2022 | 1123 | 16 | 60 |
| 14/07/2022 | 1123 | 17 | 10 |
Is there a method of using the lambda function in python to iterate through the rows of the "Job duration" column to speed the process? Thanks in advance.