I have simplified it as much as possible, try the below:
import numpy as np
df['CLASS'] = np.where(df['RISK_RATING'].str.contains('PEP'),'PEP','SF')
df['CLASS'] = np.where(df['RISK_RATING'].isnull(),'missing',df['CLASS'])
Will get you:
BUSINESS CUSTOMER_ID RISK_RATING CLASS
0 PVB 1000033280 HR SF
1 PVB 1000166304 PEP (SR) PEP
2 PVB 1004006928 PEP (SR) PEP
3 PVB 1004006936 PEP (SR) PEP
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…