Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse of pyspark.sql.functions greatest

Is there an inverse to the function greatest? Something to get the min of multiple columns?

If there is not, do you know any other way to find it than using udf functions?

Thank you!

like image 768
Anneso Avatar asked Jan 17 '26 13:01

Anneso


1 Answers

The inverse is:

pyspark.sql.functions.least(*cols)

Returns the least value of the list of column names, skipping null values. This function takes at least 2 parameters. It will return null iff all parameters are null.

>>> df = spark.createDataFrame([(1, 4, 3)], ['a', 'b', 'c'])
>>> df.select(least(df.a, df.b, df.c).alias("least")).collect()
[Row(least=1)]
like image 130
Alper t. Turker Avatar answered Jan 21 '26 07:01

Alper t. Turker