I have a dataframe with occ empty:
ID occ
a
a
b
a
b
c
Now I want to make another column that will count the number of occurence and only show the count in first row and rest should remain "1":
expected result
ID occ
a 3
a 1
b 2
a 1
b 1
c 1
In here 'a' is 3 times, 'b' is 2 times and 'c' is 1 times. All other rows of a and b are to be shown 1.
I got the count by :
df['ID'].value_counts()
but it throws an error when I try to put it in a dataframe using:
df['occ']=df['Value'].value_counts()
TypeError: unhashable type: 'list'