Select to view content in your preferred language

How to duplicate rows in a table/feature class (modelbuilder)

3462
2
02-06-2017 10:13 AM
KaanEroglu
Deactivated User

Hello!

I am trying to duplicate values from the first row of my table to the other rows. 

This screenshot is showing my first row with values 75, 226 and 86.

I would like to copy these values into other 6 rows and make it look like the one below;

I can do this manually by entering the first value into the field calculator (do it for each fields). However, I am trying to build a model that does it automatically. I am trying to find a tool that takes the value from first row and assigns to the others.

Thanks

0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor

You should look into the Get Field Value tool, and then use the returned value in the field calculator.

Get Field Value—Help | ArcGIS for Desktop 

0 Kudos
MitchHolley1
MVP Regular Contributor
import arcpy

table = r'path to table'

with arcpy.da.SearchCursor(table, ['Arsons','Burglaries','Assault']) as cursor:
    for row in cursor:
        if row[0] is not None:
            row0value = row[0]
        if row[1] is not None:
            row1value = row[1]
        if row[2] is not None:
            row2value = row[2]


arcpy.CalculateField_management(table, "Arsons", row0value)
arcpy.CalculateField_management(table, "Burglaries", row1value)
arcpy.CalculateField_management(table, "Assault", row2value)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This is assuming all data in the table is Null except for the value wanting to be copied.  I haven't tested it.