Trying to replace a string based on column value, getting the error
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
if df['Target'] == 'U':
df['Target'] = df['Action']
Getting the Error
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Just I need to check the string and replace it with another column value if matches
解决方案
Use np.where
Ex:
import numpy as np
df['Target'] = np.where(df['Target'] == "U", df['Action'], df['Target'])