0

Im trying to do a multiple join, with the following:

host_data = temp_merged_data.merge(desc_data, left_on=['device_id, port'], how='left')

However am receiving the error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/pandas/core/frame.py", line 6389, in merge
    copy=copy, indicator=indicator, validate=validate)
  File "/usr/local/lib/python3.6/site-packages/pandas/core/reshape/merge.py", line 61, in merge
    validate=validate)
  File "/usr/local/lib/python3.6/site-packages/pandas/core/reshape/merge.py", line 546, in __init__
    self._validate_specification()
  File "/usr/local/lib/python3.6/site-packages/pandas/core/reshape/merge.py", line 1059, in _validate_specification
    if len(self.right_on) != len(self.left_on):
TypeError: object of type 'NoneType' has no len()

temp_merged_data sample:

   mac_address  device_id device_type     ip_address      port  vlan
0000.001d.f805        304      Switch    10.10.10.1      None   5.0
0000.001d.f10a         89      Router  10.10.10.129      None   10.0
0000.001d.f0a3         89      Router  10.10.10.193      None   15.0
0000.001d.f024        303      Switch  10.10.10.225     Gi0/23  20.0
0101.001d.79a2        303      Switch   10.10.10.26     Gi0/3   5.0

desc_data sample:

                description  device_id device_type mac_address      port
    *** UPLINK to SW-03 ***        303      Switch                Gi0/23
       *** UPLINK to SW ***        303      Switch                Gi0/24
               *** CCTV ***        304      Switch                Gi0/21
    *** UPLINK to SW-03 ***        304      Switch                Gi0/23
       *** UPLINK to SW ***        304      Switch                Gi0/24

I want to be able to merge the port description into the temp_mergedata frame if it exists, if it doesnt leave the original data as is.

Thanks

1
  • you might have to specify the right_on as well. It is evident from the error msg Commented Jul 24, 2018 at 17:08

1 Answer 1

3
host_data = temp_merged_data.merge(desc_data, left_on=['device_id', 'port'], how='left', right_on=['device_id', 'port'])

Or as suggested by @Scott If field list is same

host_data = temp_merged_data.merge(desc_data, on=['device_id', 'port'], how='left')
Sign up to request clarification or add additional context in comments.

2 Comments

If left_on is the same as right_on just use on.
Thanks @ScottBoston

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.