DataRow
DataRow represents a single record, one piece of data within a DataFrame
Row functions
index(): Int— sequential row number inDataFrame, starts from 0;prev(): DataRow?— previous row (nullfor the first row);next(): DataRow?— next row (nullfor the last row);diff(T) { rowExpression }: T / diffOrNull { rowExpression }: T?— difference between the results of a row expression calculated for the current and previous rows;explode(columns): DataFrame<T>— spread lists andDataFrameobjects vertically into new rows;values(): List<Any?>— list of all cell values from the current row;valuesOf<T>(): List<T>— list of values of the given type ;columnsCount(): Int— number of columns;columnNames(): List<String>— list of all column names;columnTypes(): List<KType>— list of all column types;namedValues(): List<NameValuePair<Any?>>— list of name-value pairs wherenameis a column name andvalueis a cell value;namedValuesOf<T>(): List<NameValuePair<T>>— list of name-value pairs where the value has the given type;transpose(): DataFrame<NameValuePair<*>>—DataFramewith two columns:name: Stringfor column names andvalue: Any?for cell values;transposeTo<T>(): DataFrame<NameValuePair<T>>—DataFramewith two columns:name: Stringfor column names andvalue: Tfor cell values;getRow(Int): DataRow— row from theDataFrameby a row index;getRows(Iterable<Int>): DataFrame—DataFramewith a subset of rows selected by absolute row indices;relative(Iterable<Int>): DataFrame—DataFramewith a subset of rows selected by relative row indices:relative(-1..1)will return the previous, current, and next row. Requested indices will be coerced to the valid range and invalid indices will be skipped;getValue<T>(columnName)— cell value of typeTby this row and the givencolumnName;getValueOrNull<T>(columnName)— cell value of typeT?by this row and the givencolumnNameornullif there's no such column;get(column): T— cell value by this row and the givencolumn;String.invoke<T>(): T— cell value of typeTby this row and the giventhiscolumn name;ColumnPath.invoke<T>(): T— cell value of typeTby this row and the giventhiscolumn path;ColumnReference.invoke(): T— cell value of typeTby this row and the giventhiscolumn;df()—DataFramethat the current row belongs to.
The following dataframe will be used in the examples below:
Row expressions
Row expressions provide a value for every row of DataFrame and are used in add, filter, forEach, update, and other operations. There are two types of row expressions, differing in what the it argument refers to:
RowExpression
RowExpression computes a new value for every selected cell given the DataRow of that cell. Both this and it keywords in RowExpression refer to the same DataRow. Row values can be accessed with or without these keywords.
RowExpression signature: DataRow.(DataRow) -> T.
RowExpression examples
add
pivot
RowValueExpression
RowValueExpression computes a new value for every selected cell given the DataRow of that cell and the current value of that cell. this refers to the current DataRow, and it refers to the current value of the cell. RowValueExpression is used after selecting columns in functions such as update or convert.
RowValueExpression signature: DataRow.(C) -> T.
RowValueExpression examples
update (expression)
convert
Row conditions
Row condition is a special case of row expression that returns Boolean. There are two types of row conditions:
RowFilter
RowFilter evaluates a DataRow and returns a Boolean indicating whether the row should be included in the result. Both this and it in RowFilter refer to the same DataRow. RowFilter is used in functions such as filter, drop, first, and count.
RowFilter signature: DataRow.(DataRow) -> Boolean.
RowFilter examples
filter
drop
first
count
RowValueFilter
RowValueFilter is used after selecting columns in functions such as update, gather, and format. Like RowFilter, it returns a Boolean indicating whether the row should be included in the result. However, unlike RowFilter, where both this and it refer to the current DataRow, RowValueFilter uses the current row as this and can also access the selected column value from this row as it.
RowValueFilter signature: DataRow.(C) -> Boolean.
RowValueFilter examples
update (condition)
gather
format
Row statistics
The following statistics are available for DataRow:
rowSumrowMeanrowStd
These statistics will be applied only to values of appropriate types, and incompatible values will be ignored. For example, if a dataframe has columns of types String and Int, rowSum() will compute the sum of the Int values in the row and ignore String values.
To apply statistics only to values of a particular type, use -Of versions:
rowSumOf<T>rowMeanOf<T>rowStdOf<T>rowMinOf<T>rowMaxOf<T>rowMedianOf<T>rowPercentileOf<T>