Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do an Merge
#1
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
Yoriz write Sep-24-2021, 06:05 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020