How to find minimum value and display it with coressponding columns

Viewed 39

I have dataframe where I want to display the min value in _c3 to the corresponding _c0 value

+-----------+----+
|        _c0| _c3|
+-----------+----+
|ITE00100554| -75|
|ITE00100554|-148|
|GM000010962|   0|
|EZE00100082| -86|
|EZE00100082|-135|
|ITE00100554| -60|

I have selected the columns as shown above and used an aggregate function to find minimum

val g = df.select($"_c0",$"_c3").agg(min($"_c3"))

df.filter($"_c2" === "TMAX")

val g = df.select($"_c0",$"_c3").agg(min($"_c3"))

but this the output i get:

+--------+
|min(_c3)|
+--------+
|      -1|
+--------+

How do I change my code to obtain the _c0 with it's minimum _c3 value next to it?

0 Answers
Related