For df:
sample type count
sample1 red 5
sample1 red 7
sample1 green 3
sample2 red 2
sample2 green 8
sample2 green 8
sample2 green 2
sample3 red 4
sample3 blue 5
I would like to find items in "type" with multiple occurences and replace the "count" for each of those with the mean count. So expected output:
sample type count
sample1 red 6
sample1 green 3
sample2 red 2
sample2 green 6
sample3 red 4
sample3 blue 5
So
non_uniq = df.groupby("sample")["type"].value_counts()
non_uniq = non_uniq.where(non_uniq > 1).dropna()
finds the "type" with multiple occurences but I don't know how to match it in df