1

I have the following code:

def func(x):
  return (1, 2, 3)

df.groupby[col].aggregate(func)

How to make three columns as the result of one aggregation function? I also tried returning np.array, pd.Series, but it doesn't help.

1
  • Can you please share sample input and expected output ? Commented Nov 1, 2016 at 12:04

1 Answer 1

3

In func() you have to return a dataframe and I believe you should use apply(), for example like so:

def func(x):
    return pd.DataFrame([1,2,3]).T

df.groupby[col].apply(func)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.