# valueCounts

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

Returns a [DataFrame](dataframe.html) containing the counts of the unique values in a [DataFrame](dataframe.html) or [DataColumn](datacolumn.html).

API reference: [valueCounts](https://kotlin.github.io/dataframe/api-docs/core/org.jetbrains.kotlinx.dataframe.api/value-counts.html)

```KOTLIN
valueCounts(sort = true, ascending = false, dropNA = true, resultColumn = "count")
     [ { columns } ]
```

See [column selectors](columnselectors.html) for how to select the columns for this operation.

Parameters:

* `sort: Boolean = true` — whether to sort by count

* `ascending: Boolean = false` — sort direction (by default most frequent first)

* `dropNA: Boolean = true` — whether to exclude [NA](nanandna.html) values from counting (excluded by default)

* `resultColumn: String = "count"` — name of the column with counts

* `columns = all` — columns to use when counting unique combinations

The following dataframe will be used in the examples below:

```KOTLIN
df
```

[Embedded content](./resources/valueCountsDf.html)

For a [DataFrame](dataframe.html), `dropNA = true` (default) excludes the entire row if any selected column contains an [NA](nanandna.html) value. [NA](nanandna.html) values in columns that are not selected do not affect the result.

```KOTLIN
df.valueCounts()
```

[Embedded content](./resources/valueCounts.html)

To include rows with [NA](nanandna.html) values, set `dropNA = false`:

```KOTLIN
df.valueCounts(dropNA = false)
```

[Embedded content](./resources/valueCountsWithNA.html)

You can specify columns that will be used to determine uniqueness:

Properties:

```KOTLIN
df.valueCounts(dropNA = false) { name }
```

Strings:

```KOTLIN
df.valueCounts("name", dropNA = false)
```

[Embedded content](./resources/valueCountsSelector.html)

This operation can also be applied to a [DataColumn](datacolumn.html):

```KOTLIN
df.age.valueCounts()
```

[Embedded content](./resources/valueCountsColumn.html)

