在F#中的Deedle时间序列中使用缺失值(1) [英] Working with missing values in Deedle Time Series in F# (1)

查看:145
本文介绍了在F#中的Deedle时间序列中使用缺失值(1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个小例子,我想处理系列自定义函数中的缺失值.

here is a small example where I want to deal with missing values on custom functions on series.

假设我已经获得了一个系列

suppose that i have obtained a series

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

例如,这种方式:

 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

然后,如果我这样做,

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

失败

System.Exception:由于操作较早而无法完成 错误``int选项''类型与``int opt''类型不匹配.看 还要输入.fsx(4,42)-(4,49).在4,42

 System.Exception: Operation could not be completed due to earlier error  The type 'int option' does not match the type 'int opt'. See also input.fsx(4,42)-(4,49). at 4,42

我希望结果是

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

甚至更好的是能够得到类似的结果

even better would be to able to get a result like

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

那里正确的语法是什么?理想情况下,如果有一个<missing>值,我想为新系列中的同一键提供一个<missing>

what would be the right syntax there ? ideally if there is a <missing> value, i would like a <missing> value for the same key in the new series

基本上我需要对int opt类型

奖金问题:对于像>"这样的常用运算符,Deedle中是否有矢量化运算符? (系列1>系列2),如果两个系列具有相同的键类型,则会返回一个新的布尔(选项?)类型系列

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

谢谢

推荐答案

您可以这样做:

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

您可以在文档中了解有关模块OptionalValue的信息.

You can read about module OptionalValue in the documentation

这篇关于在F#中的Deedle时间序列中使用缺失值(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆