2016-12-03 74 views
1

我是C#/ F#的新手。在C#中展示Deedle的在線資源非常有限,但我確實需要使用C#來進行數據分析。C#轉換之間的Deedle幀和DataTable

的樣品數據Titanic.csv,從這裏開始: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. 

     } 
    } 
} 

回答

0

您需要Frame.Records的集合。 A DataTable不是一個集合,而是它的Rows成員。你可以這樣做:

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

這是不對的。 Frame.FromRecords對傳入的對象的屬性執行反射。如果按照您的建議進行操作,它將從DataRow上的屬性創建一個Frame,而不是其中的項目。 – MgSam

+0

@MgSam你是對的。你介意分享任何其他解決方案來解決我的問題嗎? – chl111

0

您可以將數據錶轉換爲DataTableReader和使用Frame.ReadReader創建框架:

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