aggregate value python code example

Example 1: python groupby sum single columns

df.groupby(['A','C'], as_index=False)['B'].sum()

Example 2: Aggregate on the entire DataFrame without group

# 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)]

Example 3: how can i aggregate without group by in pandas

df.groupby(lambda _ : True).agg(new_col_name = ('col_name', 'agg_function'))