XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.0
    • Fix Version/s: None
    • Component/s: PySpark, SQL
    • Labels:
      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()
      
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              smilegator Xiao Li
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated: