I am trying to concatenate two columns in pandas dataframe based on certain conditions, but I am getting this error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Below is what I am trying to do:
if df['Origin Region1'] == "EUR":
df['Org_Region'] = df['Origin Region1'] + '' + df['Origin Region']
elif df['Origin Region1'] == "ASIA":
df['Org_Region'] = df['Origin Region1'] ``+ '' + df['Origin Region']
Please help!
Try:
df['Org_Region'][df['Org_Region1'].isin(['EUR', 'ASIA'])] =
df['Origin Region1'] + ' ' + df['Origin Region']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.