Merging 2 pandas dataframes on key with duplicates but do not want it to result in two lines I am trying to merge a &quot;roster&quot; where there are supposed to be several positions with one person per office. However, I have come across two instances where there are two people in one position for one office. I am storing this information into a preset &quot;key&quot; for what the offices are... so when there are two individuals for one position in one office it just duplicates the information except for where there was the NAME1/NAME2.  The first line will use NAME1 and the second line will use NAME2.
For example:
key1  ...    NAME1
key1  ...    NAME2
key2  ...    NAME3
key3  ...    NAME4

I'd like to make this end up as:
key1  ...    NAME1/NAME2
key2  ...    NAME3
key3  ...    NAME4

So that the duplicates are merged by adding a / ... This should be as simple as string concatenation. But I am struggling without making a bunch of loops to do this.
Without a reproducible exmple is difficult but I would go with something like this:
df = pd.DataFrame({&quot;key_column&quot;:[&quot;key1&quot;,&quot;key1&quot;,&quot;key2&quot;,&quot;key3&quot;],&quot;name_column&quot;:[&quot;NAME1&quot;,&quot;NAME2&quot;,&quot;NAME3&quot;,&quot;NAME4&quot;]})

df.groupby(&quot;key_column&quot;).name_column.apply(lambda x: &quot;/&quot;.join(list(x)))

Result:
key_column
key1    NAME1/NAME2
key2          NAME3
key3          NAME4
Name: name_column, dtype: object