pivotMatches
Computes a presence matrix (similar to one-hot encoding) for the values in the specified columns of this DataFrame, returning a new DataFrame where:
Columns represent all unique values from the selected
columns(they becomecolumn groupscorresponding to value combinations when usingthen, similar topivot);Rows correspond to all unique combinations of values from the remaining columns; each combination is represented in dedicated key columns that store a distinct set of values for each row (similar to
keysinGroupBy).Cells contain a
Booleanvalue indicating whether a row with the corresponding combination of values (horizontal and vertical) exists in theDataFrame.
This function combines pivot, groupByOther, and matches operations into a single call.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See pivotMatches on the documentation website.
See also:
pivotCounts, which performs a similar operation but counts the number of matching rows instead of checking for their presence to produce a count matrix.
This pivotMatches Overload
Select or express pivot columns using the PivotDsl.
PivotDsl defines how key columns are selected and structured in a pivot:
pivotwith a single key column produces aPivotcontaining one column for each unique key (i.e., key column unique values) with the corresponding group;pivotwith multiple keys combined usingandproduces aPivotwith independentcolumn groupsfor each key column, each having subcolumns with the keys corresponding to their unique values;pivotwith multiple keys ordered usingthenproduces aPivotwith nestedcolumn groups, representing a hierarchical structure of keys combinations from the pivoted columns — i.e., one group per unique key combination.
Examples
// Pivot by the "city" column
df.pivot { city }
// Independent pivot by "city" and "lastName" (from the "name" column group)
df.pivot { city and name.lastName }
// Hierarchical pivot by two columns with composite ("city", "lastName") keys
df.pivot { city then name.lastName }Example
// Compute whether matching rows exist for all unique values of "city"
// and "name" (independently) across all possible combinations
// of values in the remaining columns.
df.pivotMatches { city and name }Return
A new DataFrame representing a Boolean presence matrix — with grouping key columns as rows, pivot key values as columns, and true/false cells indicating existing combinations.
Parameters
If true (default), the generated pivoted columns are nested inside the original column; if false, they are placed at the top level.
The Pivot Columns Selector that defines which columns are used as pivot keys for the operation.
Computes a presence matrix (similar to one-hot encoding) for the values in the specified columns of this DataFrame, returning a new DataFrame where:
Columns represent all unique values from the selected
columns(they becomecolumn groupscorresponding to value combinations when usingthen, similar topivot);Rows correspond to all unique combinations of values from the remaining columns; each combination is represented in dedicated key columns that store a distinct set of values for each row (similar to
keysinGroupBy).Cells contain a
Booleanvalue indicating whether a row with the corresponding combination of values (horizontal and vertical) exists in theDataFrame.
This function combines pivot, groupByOther, and matches operations into a single call.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See pivotMatches on the documentation website.
See also:
pivotCounts, which performs a similar operation but counts the number of matching rows instead of checking for their presence to produce a count matrix.
This pivotMatches Overload
Select single or multiple columns using their names as Strings. (String API).
Example
// Compute whether matching rows exist for all unique values of "city"
// and "name" (independently) across all possible combinations
// of values in the remaining columns.
df.pivotMatches("city", "name")Return
A new DataFrame representing a Boolean presence matrix — with grouping key columns as rows, pivot key values as columns, and true/false cells indicating existing combinations.
Parameters
Defines whether the generated columns are nested under a supercolumn:
true— pivot key columns are nested under a supercolumn named after the original pivoted column (independently for multiple pivoted columns);false— pivot key columns are not nested (i.e., placed at the top level);null(default) — inferred automatically:truefor multiple pivoted columns or when the Pivot has been grouped;falseotherwise.
The Column Names that defines which columns are used as pivot keys for the operation.
Computes a presence matrix (similar to one-hot encoding) for the values in the specified columns within each group of this GroupBy, returning a new DataFrame where:
Columns represent all unique values from the selected
columns(they becomecolumn groupscorresponding to value combinations when usingthen, similar topivot);Rows correspond to all unique combinations of values from the grouping columns; each combination is represented in dedicated key columns that store a distinct set of values for each row (similar to
keysinGroupBy).Cells contain a
Booleanvalue indicating whether a row with the corresponding combination of values (horizontal and vertical) exists in theDataFrame.
This function combines pivot and matches operations into a single call.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See pivotMatches on the documentation website.
See also: pivotCounts, which performs a similar operation but counts the number of matching rows instead of checking for their presence.
This pivotMatches Overload
Select or express pivot columns using the PivotDsl.
PivotDsl defines how key columns are selected and structured in a pivot:
pivotwith a single key column produces aPivotcontaining one column for each unique key (i.e., key column unique values) with the corresponding group;pivotwith multiple keys combined usingandproduces aPivotwith independentcolumn groupsfor each key column, each having subcolumns with the keys corresponding to their unique values;pivotwith multiple keys ordered usingthenproduces aPivotwith nestedcolumn groups, representing a hierarchical structure of keys combinations from the pivoted columns — i.e., one group per unique key combination.
Examples
// Pivot by the "city" column
df.pivot { city }
// Independent pivot by "city" and "lastName" (from the "name" column group)
df.pivot { city and name.lastName }
// Hierarchical pivot by two columns with composite ("city", "lastName") keys
df.pivot { city then name.lastName }Example
// Compute whether matching rows exist for all unique values of "city"
// and "name" (independently) across all grouping key combinations
gb.pivotMatches { city and name }Return
A new DataFrame representing a Boolean presence matrix — with grouping key columns as rows, pivot key values as columns, and true/false cells indicating existing combinations.
Parameters
Defines whether the generated columns are nested under a supercolumn:
true(default) — pivot key columns are nested under a supercolumn named after the original pivoted column (independently for multiple pivoted columns);false— pivot key columns are not nested (i.e., placed at the top level);
The Pivot Columns Selector that defines which columns are used as pivot keys for the operation.
Computes a presence matrix (similar to one-hot encoding) for the values in the specified columns within each group of this GroupBy, returning a new DataFrame where:
Columns represent all unique values from the selected
columns(they becomecolumn groupscorresponding to value combinations when usingthen, similar topivot);Rows correspond to all unique combinations of values from the grouping columns; each combination is represented in dedicated key columns that store a distinct set of values for each row (similar to
keysinGroupBy).Cells contain a
Booleanvalue indicating whether a row with the corresponding combination of values (horizontal and vertical) exists in theDataFrame.
This function combines pivot and matches operations into a single call.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See pivotMatches on the documentation website.
See also: pivotCounts, which performs a similar operation but counts the number of matching rows instead of checking for their presence.
This pivotMatches Overload
Select single or multiple columns using their names as Strings. (String API).
Example
// Compute whether matching rows exist for all unique values of "city"
// and "name" (independently) across all grouping key combinations
df.pivotMatches("city", "name")Return
A new DataFrame representing a Boolean presence matrix — with grouping key columns as rows, pivot key values as columns, and true/false cells indicating existing combinations.
Parameters
Defines whether the generated columns are nested under a supercolumn:
true(default) — pivot key columns are nested under a supercolumn named after the original pivoted column (independently for multiple pivoted columns);false— pivot key columns are not nested (i.e., placed at the top level);
The Column Names that defines which columns are used as pivot keys for the operation.
Computes the pivotMatches statistic for the selected columns within each group and adds it to the aggregate result.
This is a shortcut for combining pivot and matches.
The resulting DataFrame columns are inserted into the final DataFrame returned by aggregate. The resulting column name can be specified using into.
See GroupBy.pivotMatches for more details.
For more information: See pivotMatches on the documentation website.
See also: pivot, pivotCounts.
This pivotMatches overload
Select or express pivot columns using the PivotDsl.
PivotDsl defines how key columns are selected and structured in a pivot:
pivotwith a single key column produces aPivotcontaining one column for each unique key (i.e., key column unique values) with the corresponding group;pivotwith multiple keys combined usingandproduces aPivotwith independentcolumn groupsfor each key column, each having subcolumns with the keys corresponding to their unique values;pivotwith multiple keys ordered usingthenproduces aPivotwith nestedcolumn groups, representing a hierarchical structure of keys combinations from the pivoted columns — i.e., one group per unique key combination.
Examples
// Pivot by the "city" column
df.pivot { city }
// Independent pivot by "city" and "lastName" (from the "name" column group)
df.pivot { city and name.lastName }
// Hierarchical pivot by two columns with composite ("city", "lastName") keys
df.pivot { city then name.lastName }Example
df.groupBy { name.firstName }.aggregate {
// Compute whether matching rows exist for all unique values of "city"
// across all "name.firstName" key values and adds it to the aggregation result
pivotMatches { city }
}Return
A new DataFrame representing a Boolean presence matrix — with grouping key columns as rows, pivot key values as columns, and true/false cells indicating existing combinations. This DataFrame is added to the aggregate result.
Parameters
Defines whether the generated columns are nested under a supercolumn:
true(default) — pivot key columns are nested under a supercolumn named after the original pivoted column (independently for multiple pivoted columns);false— pivot key columns are not nested (i.e., placed at the top level);
The Pivot Columns Selector that defines which columns are used as keys for pivoting and in which order.
Computes the pivotMatches statistic for the selected columns within each group and adds it to the aggregate result.
This is a shortcut for combining pivot and matches.
The resulting DataFrame columns are inserted into the final DataFrame returned by aggregate. The resulting column name can be specified using into.
See GroupBy.pivotMatches for more details.
For more information: See pivotMatches on the documentation website.
See also: pivot, pivotCounts.
This pivotMatches overload
Select single or multiple columns using their names as Strings. (String API).
Example
df.groupBy("firstName").aggregate {
// Compute whether matching rows exist for all unique values of "city"
// across all "firstName" key values and adds it to the aggregation result
pivotMatches("city")
}Return
A new DataFrame representing a Boolean presence matrix — with grouping key columns as rows, pivot key values as columns, and true/false cells indicating existing combinations. This DataFrame is added to the aggregate result.
Parameters
Defines whether the generated columns are nested under a supercolumn:
true(default) — pivot key columns are nested under a supercolumn named after the original pivoted column (independently for multiple pivoted columns);false— pivot key columns are not nested (i.e., placed at the top level);
The Column Names that defines which columns are used as keys for pivoting and in which order.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html