1

I've been looking through these threads, i found something similar and thought it could be the answer, but it doen't seem to work for me...

I could do this the slow way with Select By Attributes, but It's time consuming and I will have to repeat it several times for other works.

I have a field called "Kultur" (String) with different codes (DG, A, FF, ...). I want to change this information into a numeric information, so i added a new field called "Kultur_Cl" (Short Integer).

In my case if "Kultur" is DG, "Kultur_Cl" should be 1. If "Kultur" is A, "Kultur_Cl" should be 2, ...

Here is what i tried :

enter image description here

And here is what it looks like in ArcMap:

enter image description here

Once it's done i would like to do : If "Kultur_Cl" = 1 then "Kultur_Pkt" = 15, if "Kultur_Cl" = 2 then "Kultur_Pkt" = 18, ... Would this go the same way, or is it different because there would only be numeric data?

Thanks for your help !!

  • You don't need to pass the DG over to the function so remove both references...also your return lines are missing indentation – user681 Aug 22 '14 at 12:24
4

first you need a double == for your test, simple = is for assignment, not testing

second you forgot the indentation and a semi-colon

def MyCalc(Kultur,DG):
    if (Kultur == DG):
        return 1
    else:
        return 2

third, DG must be identified as a string

MyCalc(!Kultur!,'DG')

it would go the same way with numeric values (you don't need quotes in this case)

  • Thank you very much !! I'm not very good with Python, still learning... Thanks again :) – BruunsIX Aug 22 '14 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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