1

This is my code and I can't figure out what's wrong with it.

Edit: It says name 'count' not defined

df1.pivot_table(index=["Unit", "Grade"],values = ["Cost", "Quantity","Transaction_num", "Order_num"], aggfunc={'Cost':[np.sum],'Quantity':[np.sum], "Transaction_num":[count],"Order_num":[count]})

I want a sum of total cost and total quantity but I want a distinct count of transaction number and order number.

1 Answer 1

2

This means you forgot a parenthesis. Properly indenting code helps ;)

df1.pivot_table(index=['Unit', 'Grade'],
                values=['Cost', 'Quantity', 'Transaction_num', 'Order_num'],
                aggfunc={'Cost': 'sum',
                         'Quantity': 'sum',
                         'Transaction_num': 'count',
                         'Order_num': 'count',
                        }
               )
Sign up to request clarification or add additional context in comments.

3 Comments

Ah! Thanks for the help. However, now I get a new error saying name 'count' is not defined
@alwayzconfused I was fixing it, check the update
what do I need to do if I want to find unique count of the last two values?

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.