# getting data from one column in a table

Discussion created by fredjhoffmann1 on May 29, 2014
Hi all,

I need to pull data from one column in a table of 4000+ tuples. Each line within this table corresponds to a polygon, the table being the attribute table of a large shapefile. I have a cost raster and basically need to find the least cost path between each poligon (so the cost from each one, to each one).

I think I have the basic outline of what needs to be done, but unsure how to phrase it in a synthax arcpy will understand. I am using ArcMap 10.2.

the idea is that if the cost between two shapefiles is below a certain threshold (x), I want them saved in a list so I can join them later. If the cost is above x, they can be ignored. For this, information about each entry within the table needs to be taken from the table. In particular for the ''n'' variable, which needs to be every tuple in the table, one after the other. The ''m'' needs to be the whole set at all times. Is there a way of doing this in arcpy? and does anybody know if there is a way of looping this, so that it will repeat itself for each polygon within the shapefile?

Also I'm having concerns regarding wether the Cost Distance tool is sufficient or Cost Path should be calculated too (added in the edited version of the code, further below).

here is the code as i see it (without proper synthax) (1st version, please ignore)

```x = threshold cost (x)
n = OBJECT ID of shapefile (so the identifier of each polygon)
m = the shapefile (with information for each polygon)
output = table with two columns: one of n and one of m #from which paired polygons will be taken and joined

n=1
while (n=<m):
if costdistance from n to m =<x:
add n and m to output
elif n=m:
skip
else:
skip

n=n+1
```

Any help with the code or other tips for this problem would be greatly appreciated!!

Best,
Fred

#####EDIT#####

I've worked on the code further, and have a more complete attempt. Now the major question is wether the CostPath is necessary at all to find the distance from one polygon to many (has anyone had experience with this?) If it is, I think a loop with the CostDistance still needs to be run first.

I would greatly appreciate any help I could get, and will of course return the favour!

here's the newer version (it can also be found on GitHub https://github.com/fredjhoffmann/arcmap/blob/master/retabling)

```#working on some python code to try to pull information from an attribute table, run it through the arcmap's cost path
#tool to select only certain data
#needs to be run through cost through cost distance first
#synthax for cost distance tool: CostDistance (in_source_data, in_cost_raster, {maximum_distance}, {out_backlink_raster})
#synthax for cost path tool: CostPath (in_destination_data, in_cost_distance_raster, in_cost_backlink_raster, {path_type}, {destination_field})

#here's the general idea of what I want to do, although synthax is a work in progress

import arcpy
arcpy.env.workspace=r'C:\Users\xxxx'
from arcpy.sa import *
arcpy.ImporToolbox(Toolboxes\System Toolboxes\Spatial Analyst Tools.tbx\Distance\Cost Distance)
arcpy.ImporToolbox(Toolboxes\System Toolboxes\Spatial Analyst Tools.tbx\Distance\Cost Path)

x = 5 #threshold cost n = OBJECTID #of shapefile attribute table (so the
identifier of each polygon) a variable that will move a m =
r'C:\Users\xxxx'the whole shapefile (with information for each polygon) cost =
r'C:\Users\xxxx' cost raster created formerly output = table #table with two
columns: one of n and one of m, destination for data that meets criteria
distance = distance[] #list of cost distance values backlink = backlink[]
#list of cost backlink values

n=1
while (n=<m):
if [CostDistance ('n', 'cost', 'x') from n to m] =<'x':
output.append(n, m)
elif n=m:
pass
else:
pass

#is the whole cost backlink and cost path tool necessary??

n=1
while (n=<m):
if CostPath (n, cost, x, "backlink") from n to m =<x: #find a way to add "backlink" result to the backlink[]
distance.append(n,m)
elif n=m:
pass
else:
pass

#anyone know if this adds to the findings?
```