-1

Let's say I have a dataframe that looks like the following:

In [186]:

df = pd.read_csv(file, engine='python',sep='\t')
df

Out[186]:
length value   parent
        
100       5       X
 90      18       X
 77      17       Y
 15      15       Y
 89      11       Z

What do I do if I want to change this datframe into the following:

value   parent
        
  23    X
  32    Y
  11    Z

I am basically summing up the column values within the same group and saving that dataframe into a separate data frame. As you can see, I am not intested in the length column.

JJbox
  • 3
  • 2
  • 1
    Welcome to Stack Overflow! Please take the [tour]. Have you done a Pandas tutorial? Grouping values and selecting/dropping columns is Pandas 101. If you have and you're stuck, then what have you tried that didn't work? You can [edit] to clarify. If you haven't, you should do that first. This site isn't built to teach the basics. BTW, for tips, check out [ask]. – wjandrea Mar 06 '23 at 21:59

1 Answers1

0

drop the length column and do

df.groupby(['parent']).sum()

documentation

wjandrea
  • 28,235
  • 9
  • 60
  • 81
add-IV
  • 66
  • 5