Unable to create a new dataframe with a preset conditions

I have tried this several times with the same error “The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().”

Code:

df = {'category': ['retail', 'retail', 'airtime', 'electronic', 'retail', 'electronic', 
'retail', 'retail','airtime'],
'default': [0, 1, 1, 1,0,1,1,1,0],
'year': [2011, 2013, 2014, 2015,2016,2017,2018,2010,2009],
'value': [6000, 6500, 3000, 1200,3200,4530,2100,1000,3400]}
df = pd.DataFrame(df)
df

def Default_prob(x):
    if x>=2800:
       return 1
    else:
       return 0
 df["Default_prob"]=df["value"].apply(Default_prob)

def Default_category(x):
    if x=="retail":
       return 1
    else:
    return 0  
df["Default_category"]=df["category"].apply(Default_category)

df['probability'] = 0
df.loc[df['Default_prob'] == 1 & df['Default_category'] == 1, 'probability'] = 1

df

The desired output should look like this enter image description here

Answer

Try:

df.loc[(df['Default_prob'] == 1) & (df['Default_category'] == 1), 'probability'] = 1

Just filtering (with no assignment) shows:

df.loc[(df['Default_prob'] == 1) & (df['Default_category'] == 1), 'probability']
0    1
1    1
4    1
Name: probability, dtype: int64