Select to view content in your preferred language

convert row values to field values

4082
5
Jump to solution
06-12-2012 01:45 PM
ElaineKuo
Regular Contributor
Hello

I have a table describing annual temperature of seasonal distributions of five birds.
Now the fields of the table are as followed:
Rowid, bird_code (classified as summer and winter), min, max, mean

Now I want to convert the row values of summer (in bird_code) into a new field, with the row of min, max, and mean.
Please kindly advise any python code to perform this task.

Thank you
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MikeMacRae
Frequent Contributor
0 Kudos
5 Replies
NobbirAhmed
Esri Alum
Use Calculate Field tool (under Data Management > Fields). The screenshot below shows an example. Here, in the expression I'm passing four field values to a function. The function is implemented in code block.

I don't know what you want to do with the three values (min, max, mean). Here, I have just converted them to string and concatanated before returning (if the bird code is summer).

[ATTACH=CONFIG]15164[/ATTACH]
0 Kudos
MikeMacRae
Frequent Contributor
0 Kudos
ElaineKuo
Regular Contributor
Thanks for the response.
sorry I forgot to mention I am using ArcGIS 9.3

Are code block or transpose field still available iin 9.3?
0 Kudos
NobbirAhmed
Esri Alum
Calculate Field is available on 9.3 and the code should work on 9.3 as well. Are you getting any error? Here is the doc for that version of ArcGIS:

http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Calculate_Field_(Data_Management)
0 Kudos
ElaineKuo
Regular Contributor
sorry for the late response.

The above link is broken.
Also, please kindly advise how to write the expression in the following code.
Thank you.
##Script Name: Make a line from points
##Description: Connect the line by points using XToools Pro
##Created By: Elaine Kuo
##Date: 03/05/2012


#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

#Set the input workspace
#GP.workspace = sys.argv[1]
#Set the workspace.
gp.Workspace= "H:/temp/test"

#Set the output workspace
#outWorkspace = sys.argv[2]
#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp"



#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Loop through every item in the list that was just generated
for fc in fcs:

    # Break out the name, no path or extension, using the describe object.
    desc = gp.describe(fc)
    featureName = desc.name

    #Validate the new feature class name for the output workspace.
    gp.Toolbox = "Data Management"

    # Add a field to this shapefile
    gp.addfield (fc, "min", "double", 6,3)
    

    # Loop through every item in the list that was just generated 
    

    gp.toolbox = "Data Management"


    expression = "!min!"
        
    gp.CalculateField_management(fc, "min", expression, "PYTHON")
      
    #Validate the new feature class name for the output workspace.
    OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

gp.AddMessage(gp.GetMessages())
print gp.GetMessages()

0 Kudos