There is a Pandas dataframe: loan_amnt int_rate 0 5000 10.65% 1 2500 15.27% 2 2400 15.96% 3 10000 13.49% 4 3000 12.69% 5 5000 7.90% 6 7000 15.96% You need to split the values of the int_rate column into categories. Important: The int_rate column is in str data format. Write a function that will create the rate_group column and add values to it as follows: 1) if int_rate > '15.00%', rate_group should be '>15' 2) if int_rate is between '10.00%' and '15.00%', then rate_group should be '10-15' You can use regex
def rate_group(x): if x > '15.00%': return '>15' if (x >= '10.00%') & (x <= '15.00%'): return '10-15' df['rate_group'] = df['int_rate'].apply(lambda x: rate_group(x))