The OpenD Programming Language

matrixAsDataFrame

Represent CSV data as dictionary of columns. Uses the first row as header.

@trusted pure
matrixAsDataFrame
(
T
)
(
return scope Slice!(T*, 2) matrix
)

Return Value

Type: StringMap!(Slice!(T*, 1, SliceKind.universal))

a string map that refers the same header and the same data.

Examples

import mir.test: should;

auto data = "a,b,c\n1,2,3\n4,5,6\n7,8,9\n10,11,12";

import mir.ndslice.topology: as, map;
auto table = data
    .csvToStringMatrix // see also csvToAlgebraicMatrix
    .matrixAsDataFrame;


table["a"].should == ["1", "4", "7", "10"];

table.keys.should == ["a", "b", "c"];
table.values
    .map!(column => column[].as!double)
    .should == [
    [1, 4, 7, 10], // first column
    [2, 5, 8, 11], // ...
    [3, 6, 9, 12]];

Meta