I have tow data frames A and B, and I want to match between names columns in tow data frames if the name is existing in data set B I need to create a new column in data set A with the Id of data set B if not existing return 0
here is the code I wrote
#data B
email name id
[email protected] amal call 6
[email protected] amal 6
[email protected] AMAL boy 6
[email protected] boy 7
[email protected] boy 7
[email protected] call AMAL 9
[email protected] boy 7
[email protected] dog 8
[email protected] dog 8
[email protected] dog 8
#data A
id name
1 amal
1 AMAL
2 call
4 dog
3 boy
first I create contains function
A.name.str.contains('|'.join(B.name))
then I tried to create a column
A["new"] = np.where(A.name.str.contains('|'.join(B.name))==True, B.id, 0)
but I get this error
ValueError: operands could not be broadcast together with shapes (5,) (10,) ()
what I expected is
id name new
1 amal 6
1 AMAL 0
2 call 0
4 dog 7
3 boy 8
any help?
fillnamethod.pd.merge(A,B, on='name', how='left')did a job, but is there any way to pass a list with words in contains function if i want to match words not an exact match