-1

I have a dataframe which has the following data

DF1

|value|condition|
+-----+---------+
| 1   |   Y     |
| 2   |   Y     |
| 3   |   Y     |
| 3   |   N     |
| 3   |   N     |
+---------------+

I want to understand what will the result of the dataframe if i have max on an aggregation

DF1.groupby(DF1).max(condition) does it give the max count of the strings which is Y, if so how do i get the max values according to the alphabetical order ?

Edit--

This is not for date or any other datatype i want it exclusively for string

Sundeep Pidugu
  • 2,377
  • 2
  • 21
  • 43

1 Answers1

2

Try this,

scala> val df1 = Seq((1,"Y"),(2,"Y"),(3,"N"),(3,"Z")).toDF("value","condition")
df1: org.apache.spark.sql.DataFrame = [value: int, condition: string]

scala> df1.show
+-----+---------+
|value|condition|
+-----+---------+
|    1|        Y|
|    2|        Y|
|    3|        N|
|    3|        Z|
+-----+---------+


scala> df1.agg(max("condition")).show
+--------------+
|max(condition)|
+--------------+
|             Z|
+--------------+
Sundeep Pidugu
  • 2,377
  • 2
  • 21
  • 43
Sathiyan S
  • 1,013
  • 6
  • 13