Merging two time series in pandas

2019-06-16 05:10发布

Apologies if this is obviously documented somewhere, but I'm having trouble discovering it. I have two TimeSeries with some overlapping dates/indices and I'd like to merge them. I assume I'll have to specify which of the two series to take the values from for the overlapping dates. For illustration I have:

s1:
2008-09-15    100
2008-10-15    101

s2:
2008-10-15    101.01
2008-11-15    102.02

and I want:

s3:
2008-09-15    100
2008-10-15    101
2008-11-15    102.02

or

s3:
2008-09-15    100
2008-10-15    101.01
2008-11-15    102.02

1条回答
在下西门庆
2楼-- · 2019-06-16 05:40

This can be achieved using combine_first:

In [11]: s1.combine_first(s2)
Out[11]:
2008-09-15    100.00
2008-10-15    101.00
2008-11-15    102.02
dtype: float64
查看更多
登录 后发表回答