本文介绍了在C#中使用Deedle添加两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供以下CSV文件

A,B
2,3
5,7
9,11

我想添加两列,结果

A,B,C
2,3,5
5,7,12
9,11,20

使用C#和Deedle.

using C# and Deedle.

using Deedle;
using System.IO;
using System.Linq;
namespace NS
{
    class AddTwoColumns
    {
        static void main(string[] args)
        {
            var root = "path/to";
            var df = Frame.ReadCsv(Path.Combine(root, "data.csv"));

            var a = df.GetColumn<int>("A");
            var b = df.GetColumn<int>("B");
            var c = df.Select(x => x.a + x.b);
            df.AddColumn("C", c);
            df.Print();
        }
    }
}

参考也不是本教程(系列框架)特别具有启发性.

Neither thereferencenor the tutorial(series,frame)is particularly illuminating.

此简单操作正确的df.Select()是什么?

What is the correct df.Select() for this simple operation?

推荐答案

ab只是Deedle.Series,可以对其执行数字运算.因此,只需添加两个系列即可完成此操作:

a and b are just Deedle.Series which you can perform numerical operations on. So, you can do this just by adding both series:

// simply add the series
var c = a + b;
df.AddColumn("C", c);
df.Print();

// output
     A B  C
0 -> 2 3  5
1 -> 5 7  12
2 -> 9 11 20

该页面的统计和计算部分您链接到的内容)简要提到了算术运算.它还提供了有关丢失数据的注释,您可能需要考虑以下问题:

The Statistics and calculations section (of the page you linked to) briefly mentions arithmetic operations. It also features a note on missing data which you might need to consider:

这篇关于在C#中使用Deedle添加两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 10:57