I have a data set that contains intersection data. Each intersection node has up to 6 links which is identified by IN_LINK and OUT_LINK attributes. I want to create a new dataset that includes the intersection node value (NODE) and all of its accompanying links as a single record.

[NODE] [LINK_1] [LINK_2] etc... 5465 45687 9831 etc...

How would I code this in python?

sample table

  • Not sure how you get 5465 45687 9831 from the attached table. For example, where did ***87 and ***1 come from?
    – Aaron
    Jun 6, 2014 at 23:04
  • Basically you want to collapse the dataset so that each node has a single record, and the attributes for that record include attributes (which may or may not be populated) that are the numbers for the links. Do in and out need to be distinguished, or is it just any link that touches this node since it appears one in is the same as another out? A diagram like your deleted question would be very helpful if you label the links/lines and nodes with their numbers. I understand what you want to do, and it can be done, but the way to do it is escaping me at the moment.
    – Chris W
    Jun 7, 2014 at 1:51
  • Please edit more details into your question.
    – Martin F
    Feb 19, 2015 at 4:34

1 Answer 1


From your screenshot I see you are using ArcGIS. I do not know if you have the required Info/Advanced license, but there is a Pivot Table tool that may do what you want. It can flatten one-to-many relationships in a table, and unlike the two related questions below, it actually creates new attribute fields for each of the values instead of writing them all to a single field. There are Python code samples, including stand-alone script, at the linked help page.

If you don't have access to the Pivot Table tool, or want to do it without relying on that, there are two questions with slightly different approach answers that partially solve the problem already here on GIS.SE:

Both provide code/script solutions, but both also write the values to a single field. If you want separate attributes, you would have to add some code that would then add the necessary number of new fields and split the values from the single field to their individual ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.