pandas 合并熊猫中的两个时间序列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16945166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:52:46  来源:igfitidea点击:

Merging two time series in pandas

pythonpandastime-series

提问by user1507844

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:

抱歉,如果这在某处显然有记录,但我很难找到它。我有两个 TimeSeries 有一些重叠的日期/索引,我想合并它们。我假设我必须指定两个系列中的哪一个从重叠日期中获取值。为了说明,我有:

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

回答by user1507844

This can be achieved using combine_first:

这可以使用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