title: Koalas GroupBy > Apply > Lambda > Series
body: <p>I am trying to port some code from Pandas to Koalas to take advantage of Spark's distributed processing. I am taking a dataframe and grouping it on A and B and then applying a series of functions to populate the columns of the new dataframe. Here is the code that I was using in Pandas:</p>
  <pre><code>new = old.groupby(['A', 'B']) \
    .apply(lambda x: pd.Series({
      'v1': x['v1'].sum(),
      'v2': x['v2'].sum(),
      'v3': (x['v1'].sum() / x['v2'].sum()),
      'v4': x['v4'].min()
      })
  )
  </code></pre>
  <p>I believe that it is working well and the resulting dataframe appears to be correct value-wise.</p>
  <p>I just have a few questions:</p>
  <ol>
  <li><p>Does this error mean that my method will be deprecated in the future?
  <code>/databricks/spark/python/pyspark/sql/pandas/group_ops.py:76: UserWarning: It is preferred to use 'applyInPandas' over this API. This API will be deprecated in the future releases. See SPARK-28264 for more details.</code></p>
  </li>
  <li><p>How can I rename the group-by columns to 'A' and 'B' instead of <code>&quot;__groupkey_0__   __groupkey_1__&quot;? </code></p>
  </li>
  <li><p>As you noticed, I had to call pd.Series -- is there a way to do this in Koalas? Calling ks.Series gives me the following error that I am unsure how to implement:
  <code>PandasNotImplementedError: The method `pd.Series.__iter__()` is not implemented. If you want to collect your data as an NumPy array, use 'to_numpy()' instead.</code></p>
  </li>
  </ol>
  <p>Thanks for any help that you can provide!</p>