0

My df is in the following Format:

enter image description here

When i do a df.groupby('Tool').sum() i get the following:

enter image description here

The expected output is the following:

enter image description here

Please guide me in achieving the desired output.

2
  • 1
    1. Do not post images of the dataframe but a Minimal, Complete and Verifiable example. 2. What have you tried until now (except the groupby.sum() line)? Did you move past that? Commented Apr 24, 2019 at 11:10
  • Apologies for posting dataframe as image. Will avoid doing it next time onwards. Commented Apr 24, 2019 at 11:14

2 Answers 2

3

Use GroupBy.agg with convert values to sets and then join by /:

df.groupby('Tool').agg(lambda x: '/'.join(set(x))) 
Sign up to request clarification or add additional context in comments.

Comments

0
#You can also use-
df.groupby('Tool').agg(min("Cost Center") as "Cost Center",min("Nature") as "Nature").show

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.