I created a function that assigns customers to a "bucket" based on their annual purchase history. The function operates as intended when I pass individual values in (curryear, last year). How do I pass all values from two sepearate columns in curryear, lastyear?
When I try the following I receive
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
My code:
#FUNCTION FOR CATEGORIZING ANNUAL CUSTOMER PURCHASE BEHAVIOR
def bucket(curryear, lastyear):
if ((lastyear > 0) & (curryear <= 0)):
return 'Attrition'
elif ((lastyear > curryear) & (curryear > 0)):
return 'Organic Attrition'
elif ((lastyear <= 0) & (curryear > 0)):
return 'New Sales'
elif ((curryear > lastyear) & (lastyear > 0)):
return 'Organic Growth'
elif ((lastyear == 0) & (curryear == 0)):
return 'None'
else:
return 'Flat'
bucket(df['2019'],df['2018'])
Here is a sample of the data I am using: Sample Data