1

I have in python frame A

enter image description here

and frame B:

enter image description here

How can I Add new column 'name' in frame A in order to display the column z value from the frame b? The common columns between the two frames are A['b'] and B['v']

I'm trying with pandas concat or merge but i'm failing.

The expected result in frame A I would have is:

enter image description here

Thanks a lot. Best Regards Giancarlo

Celius Stingher
  • 11,967
  • 4
  • 12
  • 37
  • Does this answer your question? [What is the difference between join and merge in Pandas?](https://stackoverflow.com/questions/22676081/what-is-the-difference-between-join-and-merge-in-pandas) – Andy_101 Feb 18 '20 at 12:22

1 Answers1

1

How is your merge failing? It should work on a left join with A as left and specifying the left_on and right_on columns:

final_output = A.merge(B,how='left',left_on='b',right_on='v').rename(columns={'z':'name'}).drop(columns='v')

Output:

     a  b    c     d   name
0  Yes  1  Yes   Buy  name1
1  Yes  2  Yes  Sell  name2
2  Yes  3  Yes   Buy  name3
3  Yes  4  Yes  Sell  name4
Celius Stingher
  • 11,967
  • 4
  • 12
  • 37