with
Converts values in columns previously selected by convert using the specified rowConverter, a row value expression applied to each row in the DataFrame.
A row value expression allows you to provide a new value for every selected cell given its row (as a receiver) and its previous value (as a lambda argument).
For more information: See convert on the documentation website.
Note
update with-, convert with- and add-like expressions use AddDataRow instead of DataRow as the DSL's receiver type. This is an extension to RowValueExpression and RowExpression that provides access to the modified/generated value of the preceding row (AddDataRow.newValue).
See Also
Convert per row colto provide a new value for every selected cell giving its column.Convert as columnto convert using a column converter
Examples:
// Select columns with json values and convert it to decoded `String`.
df.convert { valueJson }.with { Json.decode(it) }
// Convert all `Int` columns to `Duration`, multiplying each value by the corresponding value from the "coeff" `Double` column before conversion
df.convert { colsOf<Int>() }.with { baseValue -> (baseValue * coeff).seconds }Return
A new DataFrame with the converted values.
Parameters
Infer strategy that defines how the type of the resulting column should be determined. Defaults to Infer.Nulls.
The RowValueExpression to provide a new value for every selected cell giving its row and previous value.
Defines how to convert values of type C into type R
For more information: See convertTo on the documentation website.
Calculates the correlation of specified columns with values in the columns previously selected with corr.
Returns a correlation matrix represented by a DataFrame, where rows and columns correspond to the selected column sets, and each cell contains the Pearson correlation coefficient between the corresponding pair of columns.
Check out Grammar.
This can include column groups and nested columns.
See also: Selecting Columns.
For more information, see: See corr on the documentation website.
This Corr With Overload
Select or express columns using the Columns Selection DSL.
This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.
The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.
Check out: Columns Selection DSL Grammar
See Column Selectors on the documentation website.
Examples
// Compute correlations between the "age" column and the "weight" and "height" columns
df.corr { age }.with { weight and height }
// Compute correlations between the "speed" column and all columns of type `Double` (excluding itself)
df.corr { speed }.with { colsOf<Double>() except speed }Return
A DataFrame containing the resulting correlation matrix.
Parameters
The ColumnsSelector used to select the second set of columns from this DataFrame to compute correlations against the initially selected columns.
Calculates the correlation of specified columns with values in the columns previously selected with corr.
Returns a correlation matrix represented by a DataFrame, where rows and columns correspond to the selected column sets, and each cell contains the Pearson correlation coefficient between the corresponding pair of columns.
Check out Grammar.
This can include column groups and nested columns.
See also: Selecting Columns.
For more information, see: See corr on the documentation website.
This Corr With Overload
Select single or multiple columns using their names as Strings. (String API).
Examples
// Compute correlations between the "age" column and the "weight" and "height" columns
df.corr("age").with("weight", "height")
// Compute correlations between the "speed" column and all columns of type `Number`
df.corr { colsOf<Number>() }.with("speed")Return
A DataFrame containing the resulting correlation matrix.
Parameters
The Column Names used to select the second set of columns from this DataFrame to compute correlations against the initially selected columns.
Creates a new FormattedFrame that uses the specified CellFormatter to format the selected cells of the dataframe.
You need to specify formatter: A lambda function expecting a CellAttributes or null given an instance of a cell: C of the dataframe.
You have access to the FormattingDsl in the context.
The formatting DSL allows you to create and combine CellAttributes to apply to one or multiple cells of a dataframe such that they have specific CSS attributes applied to them when rendered to HTML.
For instance, to specify black, bold text on a white background, you could write:
background(white) and textColor(black) and bold
It's also possible to define your own colors using rgb or interpolate colors using linear.
Use attr if you want to specify a custom CSS attribute.
For more information: See format on the documentation website.
Examples using with:
df.format()
.at(df.indices().step(2).toList())
.with { background(lightGray) and bold and textColor(black) }Check out the full Grammar.
Experimental API. It may be changed in the future.
Creates a new FormattedFrame that uses the specified HeaderColFormatter to format the selected headers.
Header formatting is additive: attributes from already-applied header formatters are combined with the newly
returned attributes using CellAttributes.and. If a parent column group is selected, its attributes are applied to its children unless explicitly overridden.
For more information: See formatHeader on the documentation website.
For an alternative supported in the compiler plugin use Convert.asColumn
With
Provide a new value for every selected cell given its row and its previous value using a row value expression.
For more information, See RowValueExpression on the documentation website.
For example:
df.update{ city }.with{ name.firstName + " from " + it }
df.update{ city }.with{ it.uppercase() }
Note
update with-, convert with- and add-like expressions use AddDataRow instead of DataRow as the DSL's receiver type. This is an extension to RowValueExpression and RowExpression that provides access to the modified/generated value of the preceding row (AddDataRow.newValue).
For more information: See update on the documentation website.
See Also
Update per colto provide a new value for every selected cell giving its column.Update per row colto provide a new value for every selected cell giving its row and column.
Parameters
The Row Value Expression to update the rows with.
Aggregates this Pivot by evaluating the given row expression on every row of each pivot group.
For each pivot cell: an empty group yields null (type V?), a group of exactly one row yields that single value (type V), and a group of several rows yields a List<V>.
If expression returns a column reference, it is resolved to that column's value in the row the expression was evaluated on.
For more information: See pivot on the documentation website.
Check out the .Pivot Grammar
Examples
df.pivot { isHappy }.with { name.lastName }df.pivot("isHappy").with { "name"["lastName"]<String>() }Return
A new DataRow with pivot keys as columns or column groups containing the computed results.
Parameters
The expression evaluated for each row within each pivot group.
Type Parameters
The result type of expression, captured at runtime for constructing the result columns.
Aggregates this ReducedPivot by evaluating the given row expression on the single row selected by the reducer in each pivot group.
For each pivot cell: a group with no row selected by the reducer yields null (type V?), otherwise the value produced by the expression (type V).
If expression returns a column reference, it is resolved to that column's value in the row the expression was evaluated on.
For more information: See pivot on the documentation website.
Examples
df.pivot { isHappy }
.maxBy { age }
.with { name.firstName + " " + name.lastName }df.pivot("isHappy")
.maxBy("age")
.with { "name"["firstName"]<String>() + " " + "name"["lastName"]<String>() }Return
A new DataRow with pivot keys as columns or column groups containing the computed results.
Parameters
The expression evaluated on each selected row.
Type Parameters
The result type of expression, captured at runtime for constructing the result columns.
Aggregates this PivotGroupBy by evaluating the given row expression on every row in each group defined by the grouping and pivot keys.
For each pivot cell: an empty group yields null (type V?), a group of exactly one row yields that single value (type V), and a group of several rows yields a List<V>.
If expression returns a column reference, it is resolved to that column's value in the row the expression was evaluated on.
For more information: See pivot on the documentation website.
Examples
df.groupBy { city }.pivot { isHappy }.with { name.lastName }
df.groupBy("city").pivot("isHappy").with { "name"["lastName"]<String>() }Return
A new DataFrame with the grouping key columns, one row per grouping key combination, and pivot keys as columns or column groups containing the computed results.
Parameters
The expression evaluated for each row within each pivot cell group.
Type Parameters
The result type of expression, captured at runtime for constructing the result columns.
Aggregates this ReducedPivotGroupBy by evaluating the given row expression on the single row selected by the reducer in each group defined by the grouping and pivot keys.
For each pivot cell: a group with no row selected by the reducer yields null (type V?), otherwise the value produced by the expression (type V).
If expression returns a column reference, it is resolved to that column's value in the row the expression was evaluated on.
For more information: See pivot on the documentation website.
Examples
df.groupBy { city }.pivot { isHappy }.maxBy { age }.with { name.lastName }
df.groupBy("city").pivot("isHappy").maxBy("age").with { "name"["lastName"]<String>() }Return
A new DataFrame with the grouping key columns, one row per grouping key combination, and pivot keys as columns or column groups containing the computed results.
Parameters
The expression evaluated on each selected row.
Type Parameters
The result type of expression, captured at runtime for constructing the result columns.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html