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.

import pandas as pd import numpy as np df = pd.DataFrame({'rate_group': ['new', 'new%', 'old', 'old%', 'new%']}) print(df)

Questions about programming?Chat with your personal AI assistant