public static DataFrame ToDataFrame(this TabularDataResource tabularDataResource)
        {
            if (tabularDataResource == null)
            {
                throw new ArgumentNullException(nameof(tabularDataResource));
            }

            var dataFrame = new DataFrame();

            foreach (var fieldDescriptor in tabularDataResource.Schema.Fields)
            {
                switch (fieldDescriptor.Type)
                {
                case TableSchemaFieldType.Number:
                    dataFrame.Columns.Add(new DoubleDataFrameColumn(fieldDescriptor.Name, tabularDataResource.Data.Select(d => Convert.ToDouble(d[fieldDescriptor.Name]))));
                    break;

                case TableSchemaFieldType.Integer:
                    dataFrame.Columns.Add(new Int64DataFrameColumn(fieldDescriptor.Name, tabularDataResource.Data.Select(d => Convert.ToInt64(d[fieldDescriptor.Name]))));
                    break;

                case TableSchemaFieldType.Boolean:
                    dataFrame.Columns.Add(new BooleanDataFrameColumn(fieldDescriptor.Name, tabularDataResource.Data.Select(d => Convert.ToBoolean(d[fieldDescriptor.Name]))));
                    break;

                case TableSchemaFieldType.String:
                    dataFrame.Columns.Add(new StringDataFrameColumn(fieldDescriptor.Name, tabularDataResource.Data.Select(d => Convert.ToString(d[fieldDescriptor.Name]))));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(dataFrame);
        }
Exemple #2
0
        public static TabularDataResourceJsonString Create(IReadOnlyDictionary <string, Type> fields, IEnumerable <IDictionary <string, object> > data)
        {
            var schema = new TableSchema();

            foreach (var entry in fields)
            {
                schema.Fields.Add(new TableSchemaFieldDescriptor(entry.Key, entry.Value.ToTableSchemaFieldType()));
            }
            var tabularDataSet = new TabularDataResource(schema, data);

            return(tabularDataSet.ToJsonString());
        }