1

Trying to run the below line

df = df.groupby(['Name', 'ID']).agg(Average_Revenue=('Amount', np.mean), Sum_Revenue=('Amount', np.sum))

but I recieve the error:

TypeError: func is expected but received tuple in **kwargs.

According to all the documentation I have looked at not sure why this is giving an error, can anyone help please

4
  • what's your pd.__version__? named aggregation requires at least v0.25.0 Commented Oct 13, 2022 at 20:37
  • I just checked and i have pandas 1.5.0 Commented Oct 13, 2022 at 20:42
  • 1
    you should post a small sample dataframe that can reproduce the error Commented Oct 13, 2022 at 20:43
  • 1
    sorry guys I just found my error, I was trying to use this line of code on a dataframe that was already grouped. I Apologize for wasting everyones time Commented Oct 13, 2022 at 20:48

1 Answer 1

1

can you post some data, versions, etc? this seems to work for me on Python 3.7.6, pandas 1.2.1, numpy 1.20.0:

import pandas as pd
import numpy as np
df = pd.DataFrame([
    ['joe', 111, 25.0],
    ['joe', 111, 30.0]
], columns=['Name', 'ID', 'Amount'])
df.groupby(['Name', 'ID']).agg(Average_Revenue=('Amount', np.mean), Sum_Revenue=('Amount', np.sum))

        Average_Revenue Sum_Revenue
Name    ID      
joe 111 27.5    55.0
Sign up to request clarification or add additional context in comments.

1 Comment

Same here (it works): Python 3.9.13, pandas 1.4.2, numpy 1.23.2

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.