I have a dataframe df that contains (among others) three columns: day
, timeTo
and goesOverDateBoundary
.
day
is a date-variable while timeTo
is a string in the format %H:%M (ex: 18:00). goesOverDateBoundary
is a boolean.
I'd like to "add" timeTo
to day
where goesOverDateBoundary
is False
and I'd like to add timeTo
to day
+ 1 where goesOverDateBoundary
is True
.
With "add" I mean that day 31-12-2020
and timeTo 18:00
becomes a datetime object 31-12-2010 18:00
. Likewise if goesOverDateBoundary
is True
the resulting object should be 01-01-2021 18:00
.
I considered iterating over the rows in my dataframe but it says here that you should "never" do that.
Example data:
+------------+--------+----------------------+------------------+
| day | timeTo | goesOverDateBoundary | resultIdLike |
+------------+--------+----------------------+------------------+
| 31-12-2020 | 18:00 | 0 | 31-12-2020 18:00 |
| 31-12-2020 | 18:00 | 1 | 01-01-2021 18:00 |
| 10-09-2020 | 03:00 | 0 | 10-09-2020 03:00 |
| 10-09-2020 | 03:00 | 1 | 11-09-2020 03:00 |
+------------+--------+----------------------+------------------+