DataFrame constructor
Creates a dataframe from the non-typed data
that is represented as
two-dimensional array, where each element is a row of table-like data.
The first element of the two-dimensional array may be a header of a
dataset:
final data = [
['column_1', 'column_2', 'column_3'], // a header
[ 20, false, 'value_1' ], // row 1
[ 51, true, 'value_2' ], // row 2
[ 22, false, null ], // row 3
]
final dataframe = DataFrame(data);
headerExists
Indicates whether the dataset header (a sequence of
column names) exists. If header exists, it must present on the very first
row of the data:
final data = [
['column_1', 'column_2', 'column_3'], // row 1
[ 20, false, 'value_1' ], // row 2
[ 51, true, 'value_2' ], // row 3
[ 22, false, null ], // row 4
]
// the first row isn't considered a header in this case, it's considered
// a data item row
final dataframe = DataFrame(data, headerExists: false);
print(dataframe.header); // should output an autogenerated header
print(dataframe.rows);
The output:
['col_0', 'col_1', 'col_2']
[
['column_1', 'column_2', 'column_3'],
[ 20, false, 'value_1' ],
[ 51, true, 'value_2' ],
[ 22, false, null ],
]
header
Predefined dataset header. It'll be skipped if headerExists
is
true. Use it to provide a custom header to a header-less dataset.
autoHeaderPrefix
A string that is used as a prefix for every column name
of auto-generated header (if headerExists
is false and header
is
empty). Underscore + ordinal number is used as a postfix of column names.
columns
A collection of column indices that specifies which columns
should be extracted from the data
and placed in the resulting DataFrame
Has a higher precedence than columnNames
columnNames
A collection of column titles that specifies which columns
should be extracted from the data
and placed in the resulting
DataFrame. It's also can be used with auto-generated column names.
The argument will be omitted if columns
is provided
Implementation
factory DataFrame(
Iterable<Iterable<dynamic>> data, {
bool headerExists = true,
Iterable<String> header = const [],
String autoHeaderPrefix = defaultHeaderPrefix,
Iterable<int> columns = const [],
Iterable<String> columnNames = const [],
}) =>
fromRawData(
data,
headerExists: headerExists,
predefinedHeader: header,
autoHeaderPrefix: autoHeaderPrefix,
columns: columns,
columnNames: columnNames,
);