Skip to content
Advertisement

Compare two DataFrames and find missing timestamps

I have the following two dataframes:

JavaScript

and in df2 I have some missing timestamps compared to df1. I am able to find those timestamps using the following code:

JavaScript

I want to populate those missing timestamps in df2 and fill in the values of the columns with the average value of the two previous rows.

So the new df2 should look like this:

JavaScript

Advertisement

Answer

Not ideal solution via iteration:

JavaScript

Output:

date col2 col3
2023-01-01 16:00:00 100.00 200.0
2023-01-01 16:15:00 120.00 400.0
2023-01-01 16:30:00 110.00 300.0
2023-01-01 16:45:00 115.00 350.0
2023-01-01 17:00:00 200.00 500.0
2023-01-01 17:15:00 157.50 425.0
2023-01-01 17:30:00 178.75 462.5
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement