Dealing with Missing Values in Deedle Time Series in F # (2)
This question is related to Dealing with Missing Values in Deedle Time Series in F # (1)
Suppose I have Series<'K,'T opt>
with some missing values
For example, I got the series
series4;;
val it : Series<int,int opt> =
1 -> 1
2 -> 2
3 -> 3
4 -> <missing>
I could get it like this:
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 values to be skipped. And this seems like a natural way to use functions in Deedle that handle missing values
So my question is asked series4 of type Series<int,int opt>
, how do I return a series with "same" values, but type Series<int,int>
????
Remarkable that strange things are happening
for example Series.dropMissing
does not have expected behavior when applied to series 4
Series.dropMissing series4;;
val it : Series<int,int opt> =
1 -> 1
2 -> 2
3 -> 3
4 -> <missing>
it does NOT drop the missing value !!
source to share
The main problem is that int opt
there is no standard Deedle way to handle missing values. There is series4
no meaning in , but it matters OptionalValue.Missing
. You can convert Series<int, int opt>
to Series<int, int>
, for example, like this:
let series4' = series4 |> Series.mapAll (fun _ v -> v |> Option.bind OptionalValue.asOption)
source to share