Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple aggregations on same column using agg in pyspark

Tags:

pyspark

I am not able to get multiple metrics using agg as below.

table.select("date_time")\
    .withColumn("date",to_timestamp("date_time"))\
    .agg({'date_time':'max', 'date_time':'min'}).show()

enter image description here

I see that second aggregation overwriting first aggregation, can someone help me to get multiple aggregations on same column?

like image 233
subro Avatar asked Feb 19 '26 16:02

subro


1 Answers

I can't replicate and make sure that it works but I would suggest instead of using a dict for your aggregations try it like this:

table.select("date_time")\
    .withColumn("date",to_timestamp("date_time"))\
    .agg(min('date_time'), max('date_time')).show()
like image 53
sophocles Avatar answered Feb 21 '26 14:02

sophocles