Is there a way to do what is done is the below question, but instead of using a single string value, use a dict/array to replace many values in less lines of code?
Replace whole string if it contains substring in pandas
What I have so far:
key = [
{
"substr": ["foo1", "foo2"],
"new_val": "bar"
},
]
for i in range(len(key)):
df.loc[df[column].str.contains('|'.join(key[i]['substr'])), column] = key[i]['new_val']
can it be improved?