Best way to get the max value in a Spark dataframe column

后端 未结 13 1065
一整个雨季
一整个雨季 2020-12-07 10:27

I\'m trying to figure out the best way to get the largest value in a Spark dataframe column.

Consider the following example:

df = spark.createDataFra         


        
13条回答
  •  眼角桃花
    2020-12-07 10:33

    First add the import line:

    from pyspark.sql.functions import min, max

    To find the min value of age in the dataframe:

    df.agg(min("age")).show()
    
    +--------+
    |min(age)|
    +--------+
    |      29|
    +--------+
    

    To find the max value of age in the dataframe:

    df.agg(max("age")).show()
    
    +--------+
    |max(age)|
    +--------+
    |      77|
    +--------+
    

提交回复
热议问题