Generation

generate functionSat, 25 Feb 2023

Write code that finds all rows in the rate_group column of Pandas with "%" at the end and removes it with regex. Rows without "%" must be replaced with np.nan.

def remove_percent(row): if row.endswith("%"): return float(row.replace("%", "")) else: return float(row) df.rate_group = df.rate_group.map(remove_percent)

Questions about programming?Chat with your personal AI assistant