This code gives an error "expected string or bytes-like object" Refactor it: import re def rate_group(int_rate): int_rate = re.sub('%', '', int_rate) int_rate = float(int_rate) if int_rate > 15.0: return '>15' elif 10.0 < int_rate <= 15.0: return '10-15' else: return '<10' df['rate_group'] = df['int_rate'].apply(rate_group)
def rate_group(int_rate): int_rate = re.sub('%', '', int_rate) int_rate = float(int_rate) if int_rate > 15.0: return '>15' elif 10.0 < int_rate <= 15.0: return '10-15' else: return '<10' df['rate_group'] = df['int_rate'].apply(rate_group)