[ https://issues.apache.org/jira/browse/SPARK-24796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16544655#comment-16544655 ]
Li Jin commented on SPARK-24796: -------------------------------- Sorry I am traveling now but I will try to take a look when I get back > Support GROUPED_AGG_PANDAS_UDF in Pivot > --------------------------------------- > > Key: SPARK-24796 > URL: https://issues.apache.org/jira/browse/SPARK-24796 > Project: Spark > Issue Type: Improvement > Components: PySpark, SQL > Affects Versions: 2.4.0 > Reporter: Xiao Li > Priority: Major > > Currently, Grouped AGG PandasUDF is not supported in Pivot. It is nice to > support it. > {code} > # 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() > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org