本文介绍了结合 pandas 中的两个时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
抱歉,如果这在某处有明显记录,但我无法找到它.我有两个 TimeSeries 有一些重叠的日期/索引,我想合并它们.我假设我必须指定两个系列中的哪一个从重叠日期中获取值.为了说明,我有:
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
我想要:
s3:
2008-09-15 100
2008-10-15 101
2008-11-15 102.02
或
s3:
2008-09-15 100
2008-10-15 101.01
2008-11-15 102.02
推荐答案
这可以使用 combine_first
:
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
这篇关于结合 pandas 中的两个时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!