1

我有两个采样率相同的时间序列。我想执行一个外连接,然后用最近的前一个填充任何丢失的数据(后外连接,可能有数据存在于一个系列中但不存在另一个系列的时间点,即使它们是相同的采样率)价值。

如何使用 Deedle 执行此操作?

编辑:

基于,我想您可以在加入之前重新采样,如下所示:

// Get the most recent value, sampled at 2 hour intervals
someSeries|> Series.sampleTimeInto
  (TimeSpan(2, 0, 0)) Direction.Backward Series.lastValue

完成此操作后,您可以安全地加入。也许还有另一种方式?

4

1 回答 1

2

您应该能够对原始系列执行外连接(最好将它们变成框架,因为这样您会得到很好的多列框架),然后填充缺失值Frame.fillMissing

// Note that s1[2] is undefined and s2[3] is undefined
let s1 = series [ 1=>1.0; 3=>3.0; 5=>5.0 ]
let s2 = series [ 1=>1.1; 2=>2.2; 5=>5.5 ]

// Build frames to make joining easier
let f1, f2 = frame [ "S1" => s1 ], frame [ "S2" => s2 ]

// Perform outer join and then fill the missing data
let f = f1.Join(f2, JoinKind.Outer)
let res = f |> Frame.fillMissing Direction.Forward

最终结果和缺失值的中间帧如下所示:

val it : Frame<int,string> =
     S1        S2        
1 -> 1         1.1       
2 -> <missing> 2.2       
3 -> 3         <missing> 
5 -> 5         5.5       

> 
val it : Frame<int,string> =
     S1 S2  
1 -> 1  1.1 
2 -> 1  2.2 
3 -> 3  2.2 
5 -> 5  5.5 

请注意,结果仍可能包含缺失值 - 如果第一个值缺失,则该fillMissing函数没有要传播的先前值,因此该系列可能以一些缺失值开始。

于 2014-04-15T15:45:28.037 回答