如何更新 Deedle 框架中的所有值?

How to update all values in a Deedle frame?

我想替换 deedle Frame / Series 中的所有值; 例如,我想将所有 -1 替换为 0.

我找不到办法。在 F# 中,似乎有一个 mapValue 函数,但在 C# 中找不到等效函数

没关系,找到一个可以完成这项工作的片段:

 void cleanupDF(Frame<int, string> df) {
    foreach(string c in new string[] {"col1","col2" }) {
        var relabeled = df.Columns[c].Select(kvp => ((int)kvp.Value ==- 1 ? 0 : (int)kvp.Value));
        df.ReplaceColumn(c, relabeled);
    }
}

在整个 Frame<R, C> 类型上还有一个 Select 方法,所以你应该可以这样写(不过我还没有测试过):

var res = df.Select((int row, string col, double v) => v == -1 ? 0 : v);