I have a dataframe with some replicated rows
item h2 h3 h4 ---------------- foo v1 ... ... foo v2 ... ... foo v1 ... ... foo v2 ... ... foo v1 ... ... foo v2 ... ... foo v1 ... ... foo v2 ... ... bar v5 ... ... bar v6 ... ... bar v7 ... ... bar v5 ... ... bar v6 ... ... bar v7 ... ... My goal is to add a column (new_id) in this dataframe which indicates an incrementing count of duplicate blocks (block being a set of rows that have the same item name) prefixed with the value in the item column (if it helps, the replicated blocks will be consecutive)
item h2 h3 h4 new_id ----------------------- foo v1 ... ... foo1 foo v2 ... ... foo1 foo v1 ... ... foo2 foo v2 ... ... foo2 foo v1 ... ... foo3 foo v2 ... ... foo3 foo v1 ... ... foo4 foo v2 ... ... foo4 bar v5 ... ... bar1 bar v6 ... ... bar1 bar v7 ... ... bar1 bar v5 ... ... bar2 bar v6 ... ... bar2 bar v7 ... ... bar2 Suggestions on how to accomplish this?