xs
Returns a cross-section of this DataFrame: only the rows in which the key columns hold the given keyValues, without those key columns.
The key columns are the first n columns of this DataFrame, where n is the number of given key values. Columns are counted from left to right; a column group is not counted itself, but the columns inside it are. If there are fewer columns than key values, an IllegalArgumentException is thrown.
See also:
xs(keyValues) { keyColumns }— selects the key columns explicitly.The Xs Operation— an overview of allxsmodes.
For more information: See xs on the documentation website.
Example
The examples below use this DataFrame, the same data as the xs page on the documentation website. firstName and lastName sit inside the name column group:
| name/firstName | name/lastName | age | city | weight | isHappy |
|---|---|---|---|---|---|
| Alice | Cooper | 15 | London | 54 | true |
| Bob | Dylan | 45 | Dubai | 87 | true |
| Charlie | Daniels | 20 | Moscow | null | false |
| Charlie | Chaplin | 40 | Milan | null | true |
| Bob | Marley | 30 | Tokyo | 68 | true |
| Alice | Wolf | 20 | null | 55 | false |
| Charlie | Byrd | 30 | Moscow | 90 | true |
With one key value the key column is the first column, name/firstName. The name group is not a key column itself, so it stays with its remaining column:
df.xs("Charlie")| name/lastName | age | city | weight | isHappy |
|---|---|---|---|---|
| Daniels | 20 | Moscow | null | false |
| Chaplin | 40 | Milan | null | true |
| Byrd | 30 | Moscow | 90 | true |
With two key values the key columns are name/firstName and name/lastName. The name group loses both of its columns and disappears:
df.xs("Charlie", "Chaplin")| age | city | weight | isHappy |
|---|---|---|---|
| 40 | Milan | null | true |
Return
A new DataFrame with the matching rows and without the key columns.
Parameters
The values that the key columns must hold.
Type Parameters
The schema marker type of this DataFrame.
Returns a cross-section of this DataFrame: only the rows in which the key columns hold the given keyValues, without those key columns.
The key columns are the columns returned by the keyColumns selector, in the order the selector returns them — not in the order they appear in the data. The selector must return exactly one column per key value; otherwise, an IllegalArgumentException is thrown.
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.
See also:
xs(keyValues)— takes the first columns as the key columns.The Xs Operation— an overview of allxsmodes.
For more information: See xs on the documentation website.
Example
The examples below use this DataFrame, the same data as the xs page on the documentation website. firstName and lastName sit inside the name column group:
| name/firstName | name/lastName | age | city | weight | isHappy |
|---|---|---|---|---|---|
| Alice | Cooper | 15 | London | 54 | true |
| Bob | Dylan | 45 | Dubai | 87 | true |
| Charlie | Daniels | 20 | Moscow | null | false |
| Charlie | Chaplin | 40 | Milan | null | true |
| Bob | Marley | 30 | Tokyo | 68 | true |
| Alice | Wolf | 20 | null | 55 | false |
| Charlie | Byrd | 30 | Moscow | 90 | true |
The key columns do not have to be the first ones — here "city" and "isHappy" are selected explicitly:
df.xs("Moscow", true) { city and isHappy }| name/firstName | name/lastName | age | weight |
|---|---|---|---|
| Charlie | Byrd | 30 | 90 |
Return
A new DataFrame with the matching rows and without the key columns.
Parameters
The values that the key columns must hold.
The Columns Selector that defines the key columns.
Type Parameters
The schema marker type of this DataFrame.
The type of the keyValues and of the columns that keyColumns selects.
Returns a cross-section of this GroupBy: only the key–group pairs in which the key columns hold the given keyValues, without those key columns.
Both parts of the GroupBy are filtered: the key–group pairs, and the rows inside the groups. The key columns are removed from keys and from the groups.
The key columns are the first n columns of keys, where n is the number of given key values. Columns are counted from left to right; a column group is not counted itself, but the columns inside it are. If there are fewer columns than key values, an IllegalArgumentException is thrown.
See also:
xs(keyValues) { keyColumns }— selects the key columns explicitly.The Xs Operation— an overview of allxsmodes.
For more information: See xs on the documentation website.
Example
The examples below use this DataFrame, the same data as the xs page on the documentation website. firstName and lastName sit inside the name column group:
| name/firstName | name/lastName | age | city | weight | isHappy |
|---|---|---|---|---|---|
| Alice | Cooper | 15 | London | 54 | true |
| Bob | Dylan | 45 | Dubai | 87 | true |
| Charlie | Daniels | 20 | Moscow | null | false |
| Charlie | Chaplin | 40 | Milan | null | true |
| Bob | Marley | 30 | Tokyo | 68 | true |
| Alice | Wolf | 20 | null | 55 | false |
| Charlie | Byrd | 30 | Moscow | 90 | true |
val gb = df.groupBy { city and isHappy }The key value is matched against the first key column, "city". Only the pairs whose "city" key is "Moscow" are kept, and "city" is removed from both parts:
gb.xs("Moscow").keys| isHappy |
|---|
| false |
| true |
gb.xs("Moscow").concat()| name/firstName | name/lastName | age | weight | isHappy |
|---|---|---|---|---|
| Charlie | Daniels | 20 | null | false |
| Charlie | Byrd | 30 | 90 | true |
Return
A new GroupBy with the matching key–group pairs and without the key columns.
Parameters
The values that the key columns must hold.
Type Parameters
The schema marker type of the grouping keys.
The schema marker type of the groups.
Returns a cross-section of this GroupBy: only the key–group pairs in which the key columns hold the given keyValues, without those key columns.
Both parts of the GroupBy are filtered: the key–group pairs, and the rows inside the groups. The key columns are removed from keys and from the groups.
The key columns are the columns returned by the keyColumns selector, in the order the selector returns them — not in the order they appear in the data. The selector must return exactly one column per key value; otherwise, an IllegalArgumentException is thrown.
A key column that exists in only one part is used in that part only. For example, a column that is not a grouping key exists only in the groups, so only the groups are filtered by it.
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.
See also:
xs(keyValues)— takes the first key columns as the key columns.The Xs Operation— an overview of allxsmodes.
For more information: See xs on the documentation website.
Example
The examples below use this DataFrame, the same data as the xs page on the documentation website. firstName and lastName sit inside the name column group:
| name/firstName | name/lastName | age | city | weight | isHappy |
|---|---|---|---|---|---|
| Alice | Cooper | 15 | London | 54 | true |
| Bob | Dylan | 45 | Dubai | 87 | true |
| Charlie | Daniels | 20 | Moscow | null | false |
| Charlie | Chaplin | 40 | Milan | null | true |
| Bob | Marley | 30 | Tokyo | 68 | true |
| Alice | Wolf | 20 | null | 55 | false |
| Charlie | Byrd | 30 | Moscow | 90 | true |
val gb = df.groupBy { city }"isHappy" is not a grouping key, so it exists only in the groups. Selecting it filters the rows inside the groups and leaves the keys as they are:
gb.xs(true) { isHappy }.keys| city |
|---|
| London |
| Dubai |
| Moscow |
| Milan |
| Tokyo |
| null |
gb.xs(true) { isHappy }.concat()| name/firstName | name/lastName | age | city | weight |
|---|---|---|---|---|
| Alice | Cooper | 15 | London | 54 |
| Bob | Dylan | 45 | Dubai | 87 |
| Charlie | Byrd | 30 | Moscow | 90 |
| Charlie | Chaplin | 40 | Milan | null |
| Bob | Marley | 30 | Tokyo | 68 |
Return
A new GroupBy with the matching key–group pairs and without the key columns.
Parameters
The values that the key columns must hold.
The Columns Selector that defines the key columns.
Type Parameters
The schema marker type of the grouping keys.
The schema marker type of the groups.
The type of the keyValues and of the columns that keyColumns selects.