Dear all,
I am trying to replace the values within cells (which in fact are short sentences) by new values (which are also short sentences) as can be seen in the figure. My desire is to replace these old values by looping through each row on the basis of if statements. Therefore I have written a small code which can be seen in the figure below.

I started by defining a function with parameter called 'X' which in fact is a column within the same attribute table (also same length) called 'BAGGERBEHANDELING'. This column originates from a different shapefile called 'Waterlopen_W23HR04' but was added using 'Add join'.
Then I have tried to use if statements when looping through the rows of X. However this would result in a TypeError: "string indices must be integers". Therefore I have written the line: Str_X = int(X). This however does not fix the problem as I get a Value Error: "invalid literal for int() with base 10: 'op de kant' ". Now I am stuck and in need for help. How can I solve a Value Error and am I fundamentally performing a wrong method?
I had previously tried to use the Regex package which resulted in a much more elegant code which is shown in the second figure. However I suggest that this function does not loop through each row but that it loops on the basis of values from the column that was used to perform 'Add join'. It would be nicer if the second code would loop through the individual rows, however I will focus only on the code from the first figure.
