Working with missing values in Deedle Time Series in F# (2)

倾然丶 夕夏残阳落幕 提交于 2019-12-13 16:32:53

问题


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 !!


回答1:


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)



来源:https://stackoverflow.com/questions/44029025/working-with-missing-values-in-deedle-time-series-in-f-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!