3

I want to merge duplicate rows by adding a new column 'count'

Initial Data frame

Final dataframe that I want

Final Dataframe that I want

rows can be in any order

PV8
  • 5,799
  • 7
  • 43
  • 87

1 Answers1

3

You can use:

df["count"] = 1
df = df.groupby(["user_id", "item_id", "total"])["count"].count().reset_index()
pissall
  • 7,109
  • 2
  • 25
  • 45