countDistinct

Returns the number of distinct rows in this DataFrame.

Compares rows based on the values in all columns and returns the number of unique row combinations.

See also:

  • distinct, which removes duplicate rows and returns a new DataFrame.

  • count, which counts the number of rows satisfying a given predicate.

For more information: See countDistinct on the documentation website.

Return

The number of distinct rows in this DataFrame.


Returns the number of distinct combinations of values in selected columns in this DataFrame.

Compares values in the selected columns and returns the number of unique values combinations.

See also:

  • distinct, which removes duplicate rows and returns a new DataFrame.

  • count, which counts the number of rows satisfying a given predicate.

For more information: See countDistinct on the documentation website.

This countDistinct 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.

Example

// Counts unique combinations of values in the "year" and "title" columns
// across all rows in the DataFrame
df.countDistinct { year and title }

Return

The number of distinct rows in this DataFrame.


fun <T> DataFrame<T>.countDistinct(vararg columns: String): Int

Returns the number of distinct combinations of values in selected columns in this DataFrame.

Compares values in the selected columns and returns the number of unique values combinations.

See also:

  • distinct, which removes duplicate rows and returns a new DataFrame.

  • count, which counts the number of rows satisfying a given predicate.

For more information: See countDistinct on the documentation website.

This countDistinct overload

Select single or multiple columns using their names as Strings. (String API).

Example

// Counts unique combinations of values in the "year" and "title" columns
// across all rows in the DataFrame
df.countDistinct("year", "title")

Return

The number of distinct rows in this DataFrame.


fun <T> Grouped<T>.countDistinct(resultName: String = "countDistinct"): DataFrame<T>

Aggregates this GroupBy by counting the number of distinct rows in each group.

Compares rows in each group based on the values in all columns. Returns a new DataFrame where each row corresponds to a group. The resulting DataFrame contains:

  • the original group key columns,

  • a new column (named resultName, default is "countDistinct") that contains the number of distinct rows in each group.

See also:

  • aggregate, which aggregates a GroupBy using the provided statistics.

  • count, which counts the number of rows in each group.

  • distinct, which removes duplicate rows and returns a new DataFrame.

  • groupBy, which groups the rows of a DataFrame based on the values in one or more specified cols.

For more information: See countDistinct on the documentation website.

Example

// Counts the number of distinct rows for each city, returning
// a new DataFrame with columns "city" and "countDistinct"
df.groupBy { city }.countDistinct()

Return

A new DataFrame with group keys and corresponding numbers of distinct rows.

Parameters

resultName

The name of the result column that will store the number of distinct rows in each group. Defaults to "countDistinct".


fun <T, C> Grouped<T>.countDistinct(resultName: String = "countDistinct", columns: ColumnsSelector<T, C>): DataFrame<T>

Aggregates this GroupBy by counting the number of distinct combinations of values in the selected columns in each group.

Compares rows in each group based on the values in the selected columns. Returns a new DataFrame where each row corresponds to a group. The resulting DataFrame contains:

  • the original group key columns,

  • a new column (named resultName, default is "countDistinct") that contains the number of distinct combinations of values in the selected columns in each group.

See also:

  • aggregate, which aggregates a GroupBy using the provided statistics.

  • count, which counts the number of rows in each group.

  • distinct, which removes duplicate rows and returns a new DataFrame.

  • groupBy, which groups the rows of a DataFrame based on the values in one or more specified cols.

For more information: See countDistinct on the documentation website.

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.

Example

// Counts unique combinations of values in the "year" and "title" columns
// for each city, returning a new DataFrame with columns "city" and "countDistinct"
df.groupBy { city }.countDistinct { year and title }

Return

A new DataFrame with group keys and corresponding numbers of distinct combinations of values in the selected columns.

Parameters

resultName

The name of the result column that will store the number of distinct combinations of values in the selected columns in each group. Defaults to "countDistinct".

columns

The ColumnsSelector used to select columns that will be considered for evaluating whether the rows are distinct.


fun <T, C> DataFrame<T>.countDistinct(vararg columns: KProperty<C>): Int
fun <T> DataFrame<T>.countDistinct(vararg columns: ColumnReference<*>): Int

Deprecated

It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html