1

I have a dataframe like

  0       1             One                       Two
Tech    Tool    First  Second  Third      First  Second  Third
Auto     UIP     23      18      5          59     56      3
 AI      ALT     45      34      11         32     12      20

Need an output like

  0       1             One                       Two                      Sum
Tech    Tool    First  Second  Third      First  Second  Third    First   Second    Third
Auto     UIP     23      18      5          59     56      3        82      74        8
 AI      ALT     45      34      11         32     12      20       77      46        31

Here for Sum First 82=23+59, Second 74=18+56, Third 8=5+3 Similarly for others. I am beginner in multiindex dataframe please help

5
  • 2
    df.groupby(level=1, axis=1).sum()? Commented Jan 6, 2021 at 17:11
  • @ash can you provide code that generates your example dataframe? Commented Jan 6, 2021 at 17:18
  • I import this file from external source in html format then i convert this into dataframe. So i don't have code to generate this dataframe Commented Jan 6, 2021 at 17:20
  • I'm saying you need to write that code and provide it here Commented Jan 6, 2021 at 17:41
  • See here for more information: stackoverflow.com/questions/20109391/… Commented Jan 6, 2021 at 17:42

1 Answer 1

1

You can try:

df.groupby(level=1, axis=1).sum()
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.