Gavin
Gavin

Reputation: 1521

pyspark save max value of a column into a parameter?

In pyspark, if I use the following code to calculate max value, I will get result like "Row(max(age)=5)]". But is there a way that I can save the output value 5 into a parameter such as max_age?

print(x.agg({"age": "max"}).collect())

Upvotes: 1

Views: 338

Answers (1)

mayank agrawal
mayank agrawal

Reputation: 2545

Yes, you can. You simply need to extract the value.

max_age = x.agg({"age": "max"}).collect()[0]['max(age)']

Upvotes: 1

Related Questions