Calculating mean value of 280 fields with Field Calculator from attribute table of shapefile?Rounding column...
How to install "rounded" brake pads
Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?
Are small insurances worth it?
Boss Telling direct supervisor I snitched
I am the light that shines in the dark
What does it take to become a wilderness skills guide as a business?
Paper published similar to PhD thesis
Is it a Cyclops number? "Nobody" knows!
How to recover against Snake as a heavyweight character?
Sort array by month and year
What exactly is the meaning of "fine wine"?
Why restrict private health insurance?
Can I negotiate a patent idea for a raise, under French law?
Is it appropriate to ask a former professor to order a library book for me through ILL?
Should I file my taxes? No income, unemployed, but paid 2k in student loan interest
Why isn't P and P/poly trivially the same?
Tool for measuring readability of English text
Short story about cities being connected by a conveyor belt
Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?
Why does a car's steering wheel get lighter with increasing speed
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
What does *dead* mean in *What do you mean, dead?*?
How does a sound wave propagate?
How do you make a gun that shoots melee weapons and/or swords?
Calculating mean value of 280 fields with Field Calculator from attribute table of shapefile?
Rounding column in attribute table using ArcGIS Field Calculator?Validating Values in Multiple Fields in an Attribute TableHow to use %value% (from For iterator) in SQL expression of Calculate Field in ModelBuilder?Using ModelBuilder or Python parser of Field Calculator to check values between two datasets?Sum value ArcGIS attribute (field calculator)Calculating fields if Null with Field CalculatorIs there a faster way to add a field based on zonal statistics to an attribute table?Using ArcGIS Field calculator with global variable?Calculate maximum value from a subset of fields ending with a standard suffixFailed to Generate Incremental ID with Following Python Code in the Code Block. What's the mistake in my code?
I have to average 280 fields in 1 field. Each field has 300 rows.
That is my problem. I think I need a python script. I don't want to create a raster for each field and then use the raster calculator in ModelBuilder with iterations...
I don't know how to make that script in Python.
In this pic, the field "Prom_P2" is what I need to fill with the mean or average of the previous 280 fields.
This is code that @BERA shared with me, and it works:
import arcpy
shapefile = r'D:PYTHON_practicapp_1998_2015.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('promedio') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
arcgis-desktop field-calculator python-parser
add a comment |
I have to average 280 fields in 1 field. Each field has 300 rows.
That is my problem. I think I need a python script. I don't want to create a raster for each field and then use the raster calculator in ModelBuilder with iterations...
I don't know how to make that script in Python.
In this pic, the field "Prom_P2" is what I need to fill with the mean or average of the previous 280 fields.
This is code that @BERA shared with me, and it works:
import arcpy
shapefile = r'D:PYTHON_practicapp_1998_2015.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('promedio') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
arcgis-desktop field-calculator python-parser
add a comment |
I have to average 280 fields in 1 field. Each field has 300 rows.
That is my problem. I think I need a python script. I don't want to create a raster for each field and then use the raster calculator in ModelBuilder with iterations...
I don't know how to make that script in Python.
In this pic, the field "Prom_P2" is what I need to fill with the mean or average of the previous 280 fields.
This is code that @BERA shared with me, and it works:
import arcpy
shapefile = r'D:PYTHON_practicapp_1998_2015.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('promedio') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
arcgis-desktop field-calculator python-parser
I have to average 280 fields in 1 field. Each field has 300 rows.
That is my problem. I think I need a python script. I don't want to create a raster for each field and then use the raster calculator in ModelBuilder with iterations...
I don't know how to make that script in Python.
In this pic, the field "Prom_P2" is what I need to fill with the mean or average of the previous 280 fields.
This is code that @BERA shared with me, and it works:
import arcpy
shapefile = r'D:PYTHON_practicapp_1998_2015.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('promedio') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
arcgis-desktop field-calculator python-parser
arcgis-desktop field-calculator python-parser
edited 11 mins ago
PolyGeo♦
53.6k1781243
53.6k1781243
asked Mar 24 '17 at 14:24
AnaAna
215
215
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can execute the code below in the Python window of ArcMap. I'm using the UpdateCursor which is like a more powerful Field Calculator. I assume all fields from which the mean is calculated have 'Lay' in field name.
import arcpy
shapefile = r'C:pathtoshapefileshapefile.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('Prom_P2') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f233413%2fcalculating-mean-value-of-280-fields-with-field-calculator-from-attribute-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can execute the code below in the Python window of ArcMap. I'm using the UpdateCursor which is like a more powerful Field Calculator. I assume all fields from which the mean is calculated have 'Lay' in field name.
import arcpy
shapefile = r'C:pathtoshapefileshapefile.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('Prom_P2') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
add a comment |
You can execute the code below in the Python window of ArcMap. I'm using the UpdateCursor which is like a more powerful Field Calculator. I assume all fields from which the mean is calculated have 'Lay' in field name.
import arcpy
shapefile = r'C:pathtoshapefileshapefile.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('Prom_P2') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
add a comment |
You can execute the code below in the Python window of ArcMap. I'm using the UpdateCursor which is like a more powerful Field Calculator. I assume all fields from which the mean is calculated have 'Lay' in field name.
import arcpy
shapefile = r'C:pathtoshapefileshapefile.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('Prom_P2') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
You can execute the code below in the Python window of ArcMap. I'm using the UpdateCursor which is like a more powerful Field Calculator. I assume all fields from which the mean is calculated have 'Lay' in field name.
import arcpy
shapefile = r'C:pathtoshapefileshapefile.shp'
field_names=[f.name for f in arcpy.ListFields(shapefile,wild_card='*Lay*')] #Create a list of all the fields with 'Lay' in field name
field_names.append('Prom_P2') #add your mean field to the list
with arcpy.da.UpdateCursor(shapefile,field_names) as cursor:
for row in cursor:
row[-1]=sum(row[:-2])/len(row[:-2]) #Calculate mean and assign this to the mean field (-1)
cursor.updateRow(row)
edited Mar 24 '17 at 18:54
answered Mar 24 '17 at 17:41
BERABERA
16.4k52043
16.4k52043
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f233413%2fcalculating-mean-value-of-280-fields-with-field-calculator-from-attribute-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown