I have the following code
ageDF.sort('Period')
.groupBy('Period')
.agg(round(sum('Age_specific_birth_rate'), 2).alias('Total Births'))
.show()
The above groups the sum of age_specific_birth_rate by Period
So the output will be like
Period|Total Births|
+------+------------+
| 2000| 395.5|
| 2001| 393.4|
| 2002| 377.3|
| 2003| 386.2|
| 2004| 395.9|
| 2005| 391.9|
| 2006| 400.4|
| 2007| 434.0|
| 2008| 437.8|
| 2009| 425.7|
| 2010| 434.0|
| 2011| 417.8|
| 2012| 418.2|
| 2013| 400.4|
| 2014| 384.3|
| 2015| 398.7|
| 2016| 374.8|
| 2017| 362.7|
| 2018| 342.2|
But I wanna display the maximum among this by Period
so when I type in the follwing code
ageDF.sort('Period')
.groupBy('Period')
.agg(round(sum('Age_specific_birth_rate'), 2).alias('Total'))
.select('Period', 'Total')
.agg(max('Total'))
.show()
I get the output
> +----------+
|max(Total)|
+----------+
| 437.8|
+----------+
But I wanna get something like
+------+------------+
|Period|max(Total) |
+------+------------+
| 2008| 395.5|
What shuold I do ?
Thank you