Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hello,
You almost got it. Indeed, the row is received as a dictionary, with the column names as keys. So you have to access the values for a given column in a row by doing:
row['columnName']
Let's say you want to replace some values in 'colA' of your dataset. Then, your code would look like this:
replacement_dict = {
'foo' : 'newfoo',
'bar' : 'newbar'
}
def process(row):
for string, replacement in replacement_dict.items():
row['colA'] = row['colA'].replace(string, replacement)
return row['colA']
This would have the following effect on an example dataset:
Note that you don't have to use a Python function processor. You can use a "Find and replace" processor, which in my opinion, is more user-friendly:
I hope that helps.
Hello,
You almost got it. Indeed, the row is received as a dictionary, with the column names as keys. So you have to access the values for a given column in a row by doing:
row['columnName']
Let's say you want to replace some values in 'colA' of your dataset. Then, your code would look like this:
replacement_dict = {
'foo' : 'newfoo',
'bar' : 'newbar'
}
def process(row):
for string, replacement in replacement_dict.items():
row['colA'] = row['colA'].replace(string, replacement)
return row['colA']
This would have the following effect on an example dataset:
Note that you don't have to use a Python function processor. You can use a "Find and replace" processor, which in my opinion, is more user-friendly:
I hope that helps.
Thanks JuanE 😊 . Wanted to use Python as I have around 400 possible replacements to search through which would be time consuming to do using Find & Replace.