valueCounts
Returns a DataFrame containing counts of unique values in this DataColumn.
The resulting DataFrame contains:
the column with the distinct values of the original
DataColumna new
Intcolumn with the number of occurrences of each value. This column is called"count"by default unless it is overridden byresultColumn.
By default, the result is sorted by count in descending order (the most frequent value first), and values (NAnulls and NaNs) are not counted.
See also:
— counts of unique rows in avalueCountsDataFrame.— the number of distinct rows or selected value combinations in acountDistinctDataFrame.— the distinct values themselves, without their counts.distinct— the total number of elements in thiscountDataColumn.
For more information: See valueCounts on the documentation website.
All summary statistics: See "Summary statistics" on the documentation website.
Example
// Counts the unique values in the "city" column,
// starting with the most frequent one
df.city.valueCounts()
// Counts the unique values in the "city" column, including `null`s,
// in the order of their first occurrence, in a column named "quantity"
df.city.valueCounts(sort = false, dropNA = false, resultColumn = "quantity")Return
A DataFrame with the distinct values of this DataColumn and their counts.
Parameters
If true (default), the result is sorted by count. Otherwise, the counted values keep the order of their first occurrence.
The sorting direction. If false (default), the most frequent values come first. Only used when sort is true.
If true (default), values (NAnulls and NaNs) are not counted and are excluded from the result.
The name of the resulting count column. Default — "count". If a column with this name is already present, the name is made unique by appending a number to it (for example, "count" becomes "count1").
Returns a DataFrame containing the counts of unique rows (or combinations of selected values) in this DataFrame.
Rows are compared by the values in the selected columns. If no columns are selected, values from all columns are used.
This can include column groups and nested columns.
The resulting DataFrame contains:
the distinct combinations of these values,
a new
Intcolumn with the number of occurrences of each combination. This column is called"count"by default unless it is overridden by resultColumn.
By default, the result is sorted by count in descending order (the most frequent combination first), and a row is not counted at all if any of its selected values is .NA
See also:
— counts of unique values in a singlevalueCountsDataColumn.— the number of distinct rows or selected value combinations, without their counts.countDistinct— the distinct rows themselves, without their counts.distinct
For more information: See valueCounts on the documentation website.
All summary statistics: See "Summary statistics" on the documentation website.
This valueCounts 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 the unique combinations of the values in the "name" and "city" columns,
// starting with the most frequent one
df.valueCounts { name and city }
// Counts the unique rows of the whole dataframe,
// including rows with `NA` values, in the order of their first occurrence
df.valueCounts(sort = false, dropNA = false)Return
A DataFrame with the distinct value combinations and their counts.
Parameters
If true (default), the result is sorted by count. Otherwise, the counted values keep the order of their first occurrence.
The sorting direction. If false (default), the most frequent values come first. Only used when sort is true.
If true (default), values (NAnulls and NaNs) are not counted and are excluded from the result.
The name of the resulting count column. Default — "count". If a column with this name is already present, the name is made unique by appending a number to it (for example, "count" becomes "count1").
The optional ColumnsSelector that selects the columns whose distinct value combinations are counted. If null or omitted, all columns are used.
Returns a DataFrame containing the counts of unique rows (or combinations of selected values) in this DataFrame.
Rows are compared by the values in the selected columns. If no columns are selected, values from all columns are used.
This can include column groups and nested columns.
The resulting DataFrame contains:
the distinct combinations of these values,
a new
Intcolumn with the number of occurrences of each combination. This column is called"count"by default unless it is overridden by resultColumn.
By default, the result is sorted by count in descending order (the most frequent combination first), and a row is not counted at all if any of its selected values is .NA
See also:
— counts of unique values in a singlevalueCountsDataColumn.— the number of distinct rows or selected value combinations, without their counts.countDistinct— the distinct rows themselves, without their counts.distinct
For more information: See valueCounts on the documentation website.
All summary statistics: See "Summary statistics" on the documentation website.
This valueCounts Overload
Select single or multiple columns using their names as Strings. (String API).
Example
// Counts the unique combinations of the values in the "name" and "city" columns,
// starting with the most frequent one
df.valueCounts("name", "city")Return
A DataFrame with the distinct value combinations and their counts.
Parameters
(optional) The names of the columns whose distinct value combinations are counted. If not supplied, all columns are selected.
If true (default), the result is sorted by count. Otherwise, the counted values keep the order of their first occurrence.
The sorting direction. If false (default), the most frequent values come first. Only used when sort is true.
If true (default), values (NAnulls and NaNs) are not counted and are excluded from the result.
The name of the resulting count column. Default — "count". If a column with this name is already present, the name is made unique by appending a number to it (for example, "count" becomes "count1").
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html