# single

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

Returns the single [row](datarow.html) in this [DataFrame](dataframe.html). Throws [NoSuchElementException](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-no-such-element-exception/) if the [DataFrame](dataframe.html) is empty, and [IllegalArgumentException](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/) if it has more than one row.

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

The examples on this page use the following [DataFrame](dataframe.html):

```KOTLIN
df
```

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

Properties:

```KOTLIN
df
    .filter { age == 45 } // one row is left after filtering
    .single()
```

Strings:

```KOTLIN
df
    .filter { "age"<Int>() == 45 } // one row is left after filtering
    .single()
```

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

If a [condition](datarow.html#row-conditions) is specified, returns the single [row](datarow.html) that matches it, and throws an exception if there is no matching row or if there is more than one.

Properties:

```KOTLIN
df.single { age == 45 } // only Bob Dylan is 45
```

Strings:

```KOTLIN
df.single { "age"<Int>() == 45 } // only Bob Dylan is 45
```

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

## singleOrNull

Returns the single [row](datarow.html) in this [DataFrame](dataframe.html), or `null` if the [DataFrame](dataframe.html) is empty or has more than one row.

Properties:

```KOTLIN
val noOne = df
    .filter { age > 50 } // df is empty after filtering
    .singleOrNull() // returns null
```

Strings:

```KOTLIN
val noOne = df
    .filter { "age"<Int>() > 50 } // df is empty after filtering
    .singleOrNull() // returns null
```

If a [condition](datarow.html#row-conditions) is specified, returns the single [row](datarow.html) that matches it, or `null` if there is no matching row or if there is more than one.

Properties:

```KOTLIN
val noOne = df.singleOrNull { age == 30 } // returns null: three people are 30
```

Strings:

```KOTLIN
val noOne = df.singleOrNull { "age"<Int>() == 30 } // returns null: three people are 30
```

