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,145
  • 4
  • 35
  • 64

1 Answers1

3

You can use:

df["count"] = 1
df = df.groupby(["user_id", "item_id", "total"])["count"].count().reset_index()
pissall
  • 6,460
  • 1
  • 20
  • 39