Details
-
Sub-task
-
Status: Resolved
-
Major
-
Resolution: Incomplete
-
2.4.0
-
None
Description
Currently, Grouped AGG PandasUDF is not supported in Pivot. It is nice to support it.
# create input dataframe from pyspark.sql import Row data = [ Row(id=123, total=200.0, qty=3, name='item1'), Row(id=124, total=1500.0, qty=1, name='item2'), Row(id=125, total=203.5, qty=2, name='item3'), Row(id=126, total=200.0, qty=500, name='item1'), ] df = spark.createDataFrame(data) from pyspark.sql.functions import pandas_udf, PandasUDFType @pandas_udf('double', PandasUDFType.GROUPED_AGG) def pandas_avg(v): return v.mean() from pyspark.sql.functions import col, sum applied_df = df.groupby('id').pivot('name').agg(pandas_avg('total').alias('mean')) applied_df.show()