Reputation: 3
New to python and I have been trying to find a solution here (close, but not exactly the same scenario).
Let's say I have 2 columns:
ID1 = ['ABC12a', 'ABC12b', 'ABC12c']
and ID2 = ['123','234','345']
I want to merge these 2 columns into 1, but only retain partial characters of column ID1 (ID1[:3]) and all of column ID2.
So the end result should look like:
ID1 = ['ABC123','ABC234','ABC345']
I tried something like:
df['ID1'] = df['ID1'].apply(lambda x: x.replace(x[:3],str(df['ID2'])))
and this did not work at all...any help is super appreciated! thanks
Upvotes: 0
Views: 46