I am using Esri ArcMap 10.3:

I have a very large table so I do no want to do this manually it will take me months (50k+ rows of data)

My table looks something like below example.

Purpose new field multi family

Of course my real table is way bigger and the 'purpose' field has many more unqiue values.

So what I would like to do is use the field calculator on my "new field" and have it add a value of 'xx' for each row that had a purpose value of 'apple' and jack'.

So basically if purpose was 'jack' or 'random' then new field will be 'xx'

This could be done with python im sure but I was just going to use the calculate field tool and write in an expression.

closed as off-topic by artwork21, PolyGeo Oct 28 '16 at 23:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – artwork21, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    For coding questions, please include your best code attempt in the question. This is a requirement for this forum for coding questions. – artwork21 Oct 28 '16 at 19:58
  • By code, in this instance, we would expect to see what you are typing into the Code Block and Expression with the Python Parser of the ArcGIS Field Calculator. – PolyGeo Oct 28 '16 at 23:02

Granted this is without Python and a smaller dataset, but what I have done in the past is:

  • Add the new field
  • Open the attribute table
  • Perform a Select by Attributes query for your target
  • Click the View Selected Records option
  • Use the field calculator to populate your new field with your values
  • 1
    you can option to skip the 4th bullet (view selected records) because the result will still be the same. Be sure the field calculator specifies to calculate only selected records (which it does by default). – jbchurchill Oct 28 '16 at 19:44
  • thanks! I didn't know that was a default option – annag Oct 28 '16 at 20:40

Open the Attribute Table and right click on the table you want to edit and select Field Calculator and select python and show codeblock

def calc(table):
     if table == "apple":
         return "XX"
     elif table == "pear":
         return "YY"
         return "ZZ"

Then in the bottom

table2 (the one you right clicked on) = calc(!table!)

table = the table that holds the values of "apple" , "pear" , "jack" etc... table2 is the table you are doing the field calculate on

with your values it should be:

def calc(PROPUSE): 
          return "MFR" 
     elif PROPUSE == "COOPERATIVE": 
          return "MFR" 

Existing = calc(!PROPUSE!)
  • Awseom this is what I was thinking, creating a function to do this my python isnt the best and your code gave me errors. "000539 : Error message from Python." This error code covers a number of Python errors: Example error 1: exceptions.TypeError: cannot concatenate 'str' and 'int' objects. The above is a Python-specific error. The calculation is attempting to add or concatenate a string and a number. Example error 2: Invalid field shape@distance The above is an error using the geometry object. The distance method is not a valid method of the geometry object. – NULL.Dude Oct 28 '16 at 20:36
  • Can you paste in a copy of what your DB looks like, usually that is a type error (trying to concatenate a string and an int, or trying to put a string in an int type field) , I just pasted that code into field calc and it worked on my end. What is the exact code you are using? – ed.hank Oct 28 '16 at 20:57
  • def calc(PROPUSE): if PROPUSE == "CONDOMINIUM": return "MFR" elif PROPUSE == "COOPERATIVE": return "MFR" else: return True Existing = calc(!PROPUSE!) – NULL.Dude Oct 28 '16 at 21:01
  • Not sure how to post code into the correct format in the 'comments' window – NULL.Dude Oct 28 '16 at 21:02
  • Why the else: return True? just leave that off. – ed.hank Oct 28 '16 at 21:03

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