Hi,
Could you explain me, how to change field value with dictionaries?
for example :
dict = {"A" : "A-150",
"B" : "B-200",
"C" : "C-250"}
And i want change A with A-150, B with B-200
Thanks !
Are you trying to retrieve the value?
dict = {"A" : "A-150",
"B" : "B-200",
"C" : "C-250"}
dict['A'] # get its value
'A-150'
I know this, but what statement should be, if I have 2000 Fields in Values Column ? Every field in this column has A, B or C value. How to change values with dict in all 2000 fields ?
def get_val(val):
""" get a dictionary value"""
dict = {"A" : "A-150", "B" : "B-200", "C" : "C-250"}
return dict[val]
# python parser
# field calculator code
# field calculator expression for a text field
get_val(!YourFieldNameHere!)
2000 fields? Do you mean 2000 rows? Your statement "2000 Fields in Values Column" is confusing since field and column describes the same aspect of a table.
Sorry, yeah I mean rows ... So like I said, I have 2000 rows and ~ 25 columns. One column is Values. So what expression would be the best ? Values column should have A-150, B-200, C-250 values. Not A,B,C. And I dont know solution for that...
the field calculator expression I posted will work unless your table is different... post a snapshot of what you are working with so people can better understand
Or set it to anything.
dict["A"] = "Anything you want it to be"
Any ideas ?
well it is clear now that you want to do this in a script, I thought you were wanting to do this in the field calculator. That is the part that wasn't clear.
You need to use the function (ie def ) with your dictionary to make the change within your tabletocsv function but I am not sure what it is doing there. Does this work without the conversion or is it an attempt to piece a script together?