Spark - extracting single value from DataFrame

You can use head

df.head().getInt(0)

or first

df.first().getInt(0)

Check DataFrame scala docs for more details


This could solve your problem.

df.map{
    row => row.getInt(0)
}.first()