0

I'm using a simple code. I try to see the result of a groupby by one column. But I have the problem that one of the results is duplicate.


#DataFrame
df = pd.DataFrame({'A': ['one', 'one', 'two', 'two', 'one'] ,
                   'B': ['Ar', 'Br', 'Cr', 'Ar','Ar'] ,
                   'C': ['12/15/2011', '11/11/2001', '08/30/2015', '07/3/1999','03/03/2000' ],
                      'D':[1,7,3,4,5]})


#Create a groupby and show the results

df.groupby['A'].apply(lambda x : print(x))

This show the result for one duplicate. What is the reason?

1 Answers1

0

From what I see, looks like you're looking for either one of the following:

df.groupby('A').apply(lambda x : x.sum())

OR

df.groupby(A').apply(lambda x: "{%s}" % ', '.join(x))

and I would recommend checking out this answer for more options: https://stackoverflow.com/a/17841294/6908282

Gangula
  • 5,193
  • 4
  • 30
  • 59