I have the following DataFrame:
item response
1 A
1 A
1 B
2 A
2 A
I want to add a column with the most given response for an item. which should result in:
item response mostGivenResponse
1 A A
1 A A
1 B A
2 C C
2 C C
I tried something like this:
df["responseCount"] = df.groupby(["ItemCode", "Response"])["Response"].transform("count")
df["mostGivenResponse"] = df.groupby(['ItemCode'])['responseCount'].transform(max)
But mostGivenResponse is now the count of the response in stead of the response itself.