Generation

generate functionSat, 25 Feb 2023

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 (in object data format) into categories. Write a function that creates a rate_group column and adds 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'

def rate_group(value): if value > 15.00: return '>15' elif 10.00 <= value <= 15.00: return '10-15' else: return '<10' df['rate_group'] = df['int_rate'].apply(rate_group) df

Questions about programming?Chat with your personal AI assistant