Assume I have two pandas dataframe with two columns of datetime as follow:
| Col_1 | Col_2 |
|---|---|
| 2023-01-02 | 2023-01-02 9:00 |
| 2023-01-03 | 2023-01-02 20:00 |
| 2023-01-04 | 2023-01-03 1:00 |
| 2023-01-05 | 2023-01-04 9:00 |
| 2023-01-08 | 2023-01-05 16:00 |
| 2023-01-06 9:00 | |
| 2023-01-08 12:00 |
And I want to fit Col_2 datetime base on Col_1 datetime with following condition:
If the datetime aheads 12pm, it stays with same date if the Col_1 has the same date, if not, it will switch the next Col_1 datetime. If the time pass or equal to 12pm, it will switch to the next date based on Col_1 datetime.
However, if the last value is pass 12pm and there is no relevant date from Col_1, just add one day base on the last day in Col_1
For example, I expect Col_2 will look like below:
| Col_1 | Col_2 |
|---|---|
| 2023-01-02 | 2023-01-02 |
| 2023-01-03 | 2023-01-03 |
| 2023-01-04 | 2023-01-03 |
| 2023-01-05 | 2023-01-04 |
| 2023-01-08 | 2023-01-08 |
| 2023-01-08 | |
| 2023-01-09 |
Is there any function to do so in pandas? Or how can I write the code?