在F#中使用Deedle时间系列中的缺失值(2) [英] Working with missing values in Deedle Time Series in F# (2)
问题描述
有关。 (1)
假设我有一个系列< K, T opt>
有一些缺失的值
例如,我已经获得了一系列的
series4 ;;
val it:系列< int,int opt> =
1 - > 1
2 - > 2
3 - > 3
4 - > <缺失>
我可以这样做:
< (1,1);(2,2);(3,3)]
let series2 = Series.of Observations [(1, 2);(2,2);(3,1);(4,4)]
let series3 = series1.Zip(series2,JoinKind.Outer);;
let series4 = series3 |> Series.mapValues fst
然而,在Deedle中,如果你做
let series1_plus_2 = series1 + series2
val series1_plus_2:Series< int,int> =
1 - > 3
2 - > 4
3 - > 4
4 - > <缺失>
你可以看到系列< int,int> 自然也允许丢失值。这似乎是使用Deedle中处理缺失值的函数的一种自然方式。所以我的问题是给出了类型为
的系列4< int,int opt>
,我如何得到一系列与相同的值,但类型系列< int,int>
????
值得注意的是,奇怪的事情正在发生
例如, Series.dropMissing
在应用到系列4时没有预期的行为
Series.dropMissing series4 ;;
val it:系列< int,int opt> =
1 - > 1
2 - > 2
3 - > 3
4 - > <缺失>
不丢失缺失的值!!
series4
中的值不会丢失,但它的值 OptionalValue.Missing
。例如,您可以将系列< int,int opt>
转换为系列< int,int>< / code> $ b
let series4'= series4 |> Series.mapAll(fun_v - > v |> Option.bind OptionalValue.asOption)
This question is related to
Working with missing values in Deedle Time Series in F# (1)
Suppose i have a Series<'K,'T opt>
with some missing values
For example i have obtained a series
series4;;
val it : Series<int,int opt> =
1 -> 1
2 -> 2
3 -> 3
4 -> <missing>
I could have got it this way:
let series1 = Series.ofObservations [(1,1);(2,2);(3,3)]
let series2 = Series.ofObservations [(1,2);(2,2);(3,1);(4,4)]
let series3 = series1.Zip(series2,JoinKind.Outer);;
let series4 = series3 |> Series.mapValues fst
However, in Deedle if you do
let series1_plus_2 = series1+series2
val series1_plus_2 : Series<int,int> =
1 -> 3
2 -> 4
3 -> 4
4 -> <missing>
you can see that the type Series<int,int>
also naturally allows for missing values. And this seems the natural way to use functions in Deedle handling missing values
So my question is given series4 of type Series<int,int opt>
, how do i get back a series with the "same" values but a type Series<int,int>
????
Notably, strange things are happening
for example, Series.dropMissing
has not the expected behaviour when applied to series4
Series.dropMissing series4;;
val it : Series<int,int opt> =
1 -> 1
2 -> 2
3 -> 3
4 -> <missing>
its NOT dropping the missing value !!
解决方案 Main problem here is that int opt
is not Deedle standard way to handle missing values. Value in series4
is not missing, but it have value OptionalValue.Missing
. You can convert Series<int, int opt>
to Series<int, int>
for example this way:
let series4' = series4 |> Series.mapAll (fun _ v -> v |> Option.bind OptionalValue.asOption)
这篇关于在F#中使用Deedle时间系列中的缺失值(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!