I need to count the times that two values are repeated in the dataframe and create a column that has that count:
I have this example dataframe:
date | cod | type |
---|---|---|
20210127 | 29 | h |
20210127 | 29 | h |
20210126 | 26 | h |
20210125 | 26 | h |
I need this:
date | cod | type | count |
---|---|---|---|
20210127 | 29 | h | 2 |
20210126 | 26 | h | 1 |
20210125 | 26 | h | 1 |
I try this like that :
df['count'] = df.apply(lamba x: df.count() if date and cod)