Generation

generate functionSat, 25 Feb 2023

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)

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)

Questions about programming?Chat with your personal AI assistant