Well, the ValueError is absolutely expected. int(some_text) only works if some_text contains only digits, like int("404").
[...] looping through the rows of X [...]
Just to be clear: The Field Calculation tool takes your function, loops through the rows of the feature class, and applies the function to each row. You don't need to do the looping yourself.
Or do you mean that your text field can have multiple lines?
If your table looks like this, use the expression below:
TextField |
links op de kant |
rechts op de kant |
niet op de kant |
def func(x):
replace_dict = {
"links op de kant": "Enkelzijdige belemmering",
"rechts op de kant": "Enkelzijdige belemmering",
}
return replace_dict.get(x, x)
If your table looks like this, use this expression instead:
TextField |
links op de kant rechts op de kant op de kant |
links op de kant niet op de kant |
op de kant None |
def func(x):
replace_dict = {
"links op de kant": "Enkelzijdige belemmering",
"rechts op de kant": "Enkelzijdige belemmering",
}
lines = x.split("\n")
new_lines = [replace_dict.get(line, line) for line in lines)
return "\n".join(new_lines)
Else post a screenshot of your table.
Have a great day!
Johannes