I would like to count the number of occurrences in a data frame without aggregating or deleting the duplicated value.
this is what I have tried thus far: df['counts']=df.no_.value_counts() df['counts']=df.groupby(no_).count()
key1 key2
a one
a two
b one
b two
a one
c two
I would like the result to look like this, the count column need only reflect the column in question (in this case key1)
key1 key2 count(key1)
a one 3
a two 3
b one 2
b two 2
a one 3
c two 1