0

First I am sorry if this is a recurrent question, but the way I tried to phrase it I did not find any repeats of it.

I have a data frame that among its columns it has one with date values and other that is a one hot encoding of the presence of an event:

date          event
20-11-2019     1
20-11-2019     1
12-3-2018      0

I am trying to find a way to obtain the number of events on each of those dates.

I tried to navigate around group by but got nowhere useful. Can anyone help me?

BENY
  • 296,997
  • 19
  • 147
  • 204
OldMan
  • 750
  • 5
  • 10

2 Answers2

2

Try groupby and sum

out = df.groupby('date',as_index=False).sum()
Out[75]: 
         date  event
0   12-3-2018      0
1  20-11-2019      2
BENY
  • 296,997
  • 19
  • 147
  • 204
0

does data.groupby('date')[['event']].sum() does what you want?

gaut
  • 2,299
  • 1
  • 11
  • 24