Dealing with Missing Values ​​in Deedle Time Series in F # (1)

Here's a small example where I want to deal with missing values ​​for UDFs in a series.

suppose i got a row

 series4;;
 val it : Series<int,int opt> =
 1 -> 1         
 2 -> 2         
 3 -> 3         
 4 -> <missing> 

      

for example 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

      

Then if I do,

 Series.mapAll (fun v -> match v with
                             | Some a -> (a>1)
                             | _-> false) series4

      

which fails with

System.Exception: The operation could not be performed due to an earlier error The type "int option" does not match the type "int opt". See also input.fsx (4.42) - (4.49). at 4.42

while I would like the result to be

val it : Series<int,bool opt> =
     1 -> false        
     2 -> true         
     3 -> true         
     4 -> false

      

even better would be to get a result similar to

val it : Series<int,int opt> =
     1 -> false         
     2 -> true         
     3 -> true         
     4 -> <missing> 

      

What would be the correct syntax there? ideally if there is a value <missing>

I would like a value <missing>

for the same key in a new series

Basically I need to do pattern matching by type int opt

Bonus question: is there a vectorized operator in Deedle for some common operators like ">"? (series1> series2) when both series have the same key types, return a new series of boolean (option?) types

thank

+3


source to share


1 answer


You can do it like this:

let series5 =
    series4
    |> Series.mapValues(OptionalValue.map(fun x -> x > 1))

      



You can read about the module OptionalValue

in the documentation

+1


source







All Articles