lundi 25 février 2019

Pandas - Replace a string by another column value on condition [duplicate]

This question already has an answer here:

I have a dataframe transactions with 2 columns source_numberand return_code

I would like to keep the string values of source number whenever the return code is not "successfully completed" and replace it with the string of numbers from return code whenever it is successfully completed.

I came up with this:

if "Successfully completed" in transactions['return_code']: transactions['source_number'] = transactions['return_code'] else: transactions['source_number']

to then remove "|Successfully completed" from the new value in source number but this does not make any modification when I run the script.

Any help is more than welcomed! Thank you

dataframe_pic

Aucun commentaire:

Enregistrer un commentaire