Skip to content
Advertisement

Multiple lambda outputs in string replacement using apply [Python]

I have a list of “states” from which I have to iterate:

states = ['antioquia', 'boyaca', 'cordoba', 'choco']

I have to iterate one column in a pandas df to replace or cut the string where the state text is found, so I try:

JavaScript

And the result is:

Result obtained

Result wanted:

Result wanted

joined column is the input and the desired output is p_joined column

If it’s possible also to find the state not only in the end of the string but check if the string contains it and replace it

Thanks in advance for your help.

Advertisement

Answer

This will do what your question asks:

JavaScript

Output:

JavaScript
Advertisement