how can i aggregate without group by in pandas 1

how can i aggregate without group by in pandas

# Aggregate on the entire DataFrame without group

df.agg({"age": "max"}).collect()
# [Row(max(age)=5)]
from pyspark.sql import functions as F
df.agg(F.min(df.age)).collect()
# [Row(min(age)=2)]

Here is what the above code is Doing:
1. We import the functions module from the pyspark.sql package.
2. We use the agg() function on the DataFrame.
3. We pass a dictionary to the agg() function.
4. The key of the dictionary is the column that we want to aggregate on.
5. The value of the dictionary is the aggregation function that we want to apply.
6. We use the collect() function to view the result.

Similar Posts