Skip to content
Advertisement

resample/interpolate time series with datetimeindex

I have two dataframes each containing one or more time series from the same time frame but sampled at different timestamps.

I’d like to merge them into a single one resampled and interpolated with the index of the first.

Here’s a sample of the first dataframe:

JavaScript

And the second one:

JavaScript

In this case the second one is more granular but that won’t be necessarily the case. I’d like to resample the second one with dates from the first. Is this possible in an elegant pandas way?

I tried reindex with the full dataframes but it complains about duplicate axis. Maybe that’s really my issue.

Advertisement

Answer

A simple new_df = pd.concat((df1,df2), axis=1) retains all information and timestamps. You can choose to resample new_df as wished.

In this specific case, you can do:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement