filter - 在 F# 中处理 Deedle 时间序列中的缺失值 (2)

标签 filter f# series missing-data deedle

这个问题与 Working with missing values in Deedle Time Series in F# (1)

假设我有一个Series<'K,'T opt>有一些缺失值

例如我获得了一系列

 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

但是,在迪德尔,如果你这样做

let series1_plus_2 = series1+series2

val series1_plus_2 : Series<int,int> =
1 -> 3         
2 -> 4         
3 -> 4         
4 -> <missing> 

你可以看到类型Series<int,int>自然也允许缺失值。这似乎是在 Deedle 中使用函数处理缺失值的自然方法

所以我的问题是 Series<int,int opt> 类型的系列4 ,我如何取回具有“相同”值但类型 Series<int,int> 的系列????

值得注意的是,奇怪的事情正在发生

例如,Series.dropMissing应用于系列 4 时没有预期的行为

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

它不会删除缺失值!!

最佳答案

这里的主要问题是 int opt不是 Deedle 处理缺失值的标准方法。值 series4没有缺失,但它有值(value)OptionalValue.Missing 。您可以转换Series<int, int opt>Series<int, int>例如这样: let series4' = series4 |> Series.mapAll (fun _ v -> v |> Option.bind OptionalValue.asOption)

关于filter - 在 F# 中处理 Deedle 时间序列中的缺失值 (2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44029025/

相关文章:

Python数据框: Add element to multiple cells with condition

python - 从包含字典列表的系列创建 pandas 数据框

javascript - X 轴上的 Highcharts 系列名称

java - 如果过滤器被声明为 Spring bean,有没有办法告诉 Spring 不要注册过滤器?

angularjs - Angular : Use Filter and OR Operator Pipe

if-statement - 将 ARRAYFORMULA 与 SUMIF 结合使用用于多个条件并结合通配符来选择给定条件的所有值

F# 将运算符视为函数

f# - 如何在 f# 中使用外部依赖项测试函数

Java整数ArrayList返回特定范围内的元素

f# - 从分组的 Observable 中提取值