xs

fun <T> DataFrame<T>.xs(vararg keyValues: Any?): DataFrame<T>

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 all xs modes.

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/firstNamename/lastNameagecityweightisHappy
AliceCooper15London54true
BobDylan45Dubai87true
CharlieDaniels20Moscownullfalse
CharlieChaplin40Milannulltrue
BobMarley30Tokyo68true
AliceWolf20null55false
CharlieByrd30Moscow90true

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/lastNameagecityweightisHappy
Daniels20Moscownullfalse
Chaplin40Milannulltrue
Byrd30Moscow90true

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")
agecityweightisHappy
40Milannulltrue

Return

A new DataFrame with the matching rows and without the key columns.

Parameters

keyValues

The values that the key columns must hold.

Type Parameters

T

The schema marker type of this DataFrame.


fun <T, C> DataFrame<T>.xs(vararg keyValues: C, keyColumns: ColumnsSelector<T, C>): DataFrame<T>

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 all xs modes.

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/firstNamename/lastNameagecityweightisHappy
AliceCooper15London54true
BobDylan45Dubai87true
CharlieDaniels20Moscownullfalse
CharlieChaplin40Milannulltrue
BobMarley30Tokyo68true
AliceWolf20null55false
CharlieByrd30Moscow90true

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/firstNamename/lastNameageweight
CharlieByrd3090

Return

A new DataFrame with the matching rows and without the key columns.

Parameters

keyValues

The values that the key columns must hold.

keyColumns

The Columns Selector that defines the key columns.

Type Parameters

T

The schema marker type of this DataFrame.

C

The type of the keyValues and of the columns that keyColumns selects.


fun <T, G> GroupBy<T, G>.xs(vararg keyValues: Any?): GroupBy<T, G>

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 all xs modes.

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/firstNamename/lastNameagecityweightisHappy
AliceCooper15London54true
BobDylan45Dubai87true
CharlieDaniels20Moscownullfalse
CharlieChaplin40Milannulltrue
BobMarley30Tokyo68true
AliceWolf20null55false
CharlieByrd30Moscow90true
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/firstNamename/lastNameageweightisHappy
CharlieDaniels20nullfalse
CharlieByrd3090true

Return

A new GroupBy with the matching key–group pairs and without the key columns.

Parameters

keyValues

The values that the key columns must hold.

Type Parameters

T

The schema marker type of the grouping keys.

G

The schema marker type of the groups.


fun <T, G, C> GroupBy<T, G>.xs(vararg keyValues: C, keyColumns: ColumnsSelector<T, C>): GroupBy<T, G>

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 all xs modes.

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/firstNamename/lastNameagecityweightisHappy
AliceCooper15London54true
BobDylan45Dubai87true
CharlieDaniels20Moscownullfalse
CharlieChaplin40Milannulltrue
BobMarley30Tokyo68true
AliceWolf20null55false
CharlieByrd30Moscow90true
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/firstNamename/lastNameagecityweight
AliceCooper15London54
BobDylan45Dubai87
CharlieByrd30Moscow90
CharlieChaplin40Milannull
BobMarley30Tokyo68

Return

A new GroupBy with the matching key–group pairs and without the key columns.

Parameters

keyValues

The values that the key columns must hold.

keyColumns

The Columns Selector that defines the key columns.

Type Parameters

T

The schema marker type of the grouping keys.

G

The schema marker type of the groups.

C

The type of the keyValues and of the columns that keyColumns selects.