chl111
chl111

Reputation: 488

C# Convert between Deedle Frame and DataTable

I am a newbie to C#/F#. There are very limited online resources demonstrating Deedle in C#, but I do need to use C# to conduct data analysis.

The sample data is Titanic.csv, from here: https://forge.scilab.org/index.php/p/rdataset/source/tree/master/csv/datasets/Titanic.csv

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Deedle;

namespace DepositDataCleaning
{
    class Program
    {
        static void Main(string[] args)
        {

    var titanic = Frame.ReadCsv(@"Titanic.csv");
    DataTable dt = titanic.ToDataTable(new string[1]{"Index"}); 
    # This works, to convert a deedle frame to .NET DataTable Format

    var new_deedleframe = Frame.FromRecords(dt); # it doesn't work.

        }
    }
}

Upvotes: 4

Views: 2220

Answers (2)

Talmage
Talmage

Reputation: 343

You can convert the DataTable to a DataTableReader and use Frame.ReadReader to create the Frame:

var new_deedleframe = Frame.ReadReader(dt.CreateDataReader())

Upvotes: 3

Rob Lyndon
Rob Lyndon

Reputation: 12681

You need a collection for Frame.Records. A DataTable isn't a collection, but its Rows member is. You can do this:

var deedleFrame = Frame.FromRecords(dt.Rows.OfType<DataRow>());

Upvotes: -1

Related Questions