Python Forum
How to do an Merge - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: How to do an Merge (/thread-35030.html)



How to do an Merge - jonah88888 - Sep-24-2021

I have a set of data A
Output:
19 101 Tampines 20 36 Mt Vernon 21 408 Fajar Rd 22 158 Tampines 23 8 Kim Tian
Then, I have another set of data B
Output:
Driver Address 0 TOM Lorong Puntong 1 NEO Old Upp Thomson 2 TIM Bishan 3 NEO Peminmpin 4 NEO Sin Ming 5 NEO Pemimpin 6 NEO Jalan Ikan Merah 7 NEO Mt Vernon 8 NEO Fajar 9 NEO Kim Tian 10 TEO Tampines
I would like the a kind of "Excel Vlookup" kindda of function i.e. I want data Set A to have the Driver.

Utlimately, I want the final output to be like
Output:
101 Tampines Teo 36 Mt Vernon Neo 408 Fajar Rd Neo 158 Tampines Teo 8 Kim Tian Neo
Do I do it below way? If yes, I faced an error

df2=pd.merge(union1, df1, how='inner', on=None, left_on=None, right_on='Address',left_index=False, right_index=False, sort=True)
Error:
ValueError: Cannot merge a Series without a name --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-286-519b6cc1e80a> in <module> ----> 1 df2=pd.merge(union1, df1, how='inner', on=None, left_on=None, right_on='Address',left_index=False, right_index=False, sort=True) ~\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate) 71 validate=None, 72 ) -> "DataFrame": ---> 73 op = _MergeOperation( 74 left, 75 right, ~\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in __init__(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, copy, indicator, validate) 569 validate=None, 570 ): --> 571 _left = _validate_operand(left) 572 _right = _validate_operand(right) 573 self.left = self.orig_left = _left ~\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in _validate_operand(obj) 2000 elif isinstance(obj, ABCSeries): 2001 if obj.name is None: -> 2002 raise ValueError("Cannot merge a Series without a name") 2003 else: 2004 return obj.to_frame() ValueError: Cannot merge a Series without a name