Pandas: resample a dataframe to match a DatetimeIndex of a different dataframe
Use reindex
:
series2.reindex(series1.index)
Output:
2020-06-16 23:16:00 22020-06-16 23:17:00 42020-06-16 23:18:00 62020-06-16 23:19:00 82020-06-16 23:20:00 102020-06-16 23:21:00 122020-06-16 23:22:00 142020-06-16 23:23:00 162020-06-16 23:24:00 182020-06-16 23:25:00 202020-06-16 23:26:00 222020-06-16 23:27:00 242020-06-16 23:28:00 262020-06-16 23:29:00 282020-06-16 23:30:00 302020-06-16 23:31:00 322020-06-16 23:32:00 342020-06-16 23:33:00 362020-06-16 23:34:00 382020-06-16 23:35:00 402020-06-16 23:36:00 422020-06-16 23:37:00 442020-06-16 23:38:00 462020-06-16 23:39:00 482020-06-16 23:40:00 50Freq: T, dtype: int64
Wouldn't a simple resample yield the results are looking for?
series2.resample('T').first()
If your goal is to merge the resampled timestamp back to the first dataset, you could do that as follows:
dt_map = {}for group_label, group_series in series2.resample('T'): dt_map.update({x:group_label for x in group_series.index})# Overwrite the indexseries2.index = series2.index.map(dt_map)
Note: If you want to perform an aggregate function, stick with the first option.
IIUC, this is what you need:
series2[series2.index.isin(series1.index)]