Hi Stack Overflow community,
I have a pandas data frame with two variables, and each variable is a pandas series. I am trying to replace values of a variable Y if variable X contains "-". I wrote my if statement as below:
if df['X'].str.contains(pat = '-'):
df['Y'] = df['X'].str.split('-').str[0]
But, I receive an error message of:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Then, I modify my code to:
if df['X'].str.contains(pat = '-').bool=="True":
df['Y'] = df['X'].str.split('-').str[0]
But this code doesn't do anything.
Please help me with this. I appreciate any suggestion.