Resampling 2 time series
Question:
I have 2 time series which each have a record every 30 seconds with a difference of about 21 seconds
;
ts1 starts at 12:30:00
And the second record at 12:30:30
ts2 starts at 12:30:21
And the second record at 12:30:51
What is the best way to merge them without losing information I want to have the same index for both
Answers:
IIUC use merge_asof
:
df = pd.merge_asof(ser1.to_frame('a'),
ser2.to_frame('b'),
left_index=True,
right_index=True)
You can have two separate columns for ts1
and ts2
, use pd.concat()
which with a default ‘outer’ join method, and resample with ffill()
, if necessary.
I have 2 time series which each have a record every 30 seconds with a difference of about 21 seconds
;
ts1 starts at 12:30:00
And the second record at 12:30:30
ts2 starts at 12:30:21
And the second record at 12:30:51
What is the best way to merge them without losing information I want to have the same index for both
IIUC use merge_asof
:
df = pd.merge_asof(ser1.to_frame('a'),
ser2.to_frame('b'),
left_index=True,
right_index=True)
You can have two separate columns for ts1
and ts2
, use pd.concat()
which with a default ‘outer’ join method, and resample with ffill()
, if necessary.