Generation

generate functionSat, 25 Feb 2023

Write code that finds all lines in the Pandas dataframe without the "%" sign and replace all their content with NaN

import pandas as pd df = pd.read_csv('studentscores.csv') def clean_data(df): for index, row in df.iterrows(): for i, item in enumerate(row): if type(item) == str: if '%' in item: df.iloc[index, i] = item.replace('%', '').replace(',', '') else: df.iloc[index, i] = float('NaN') return df clean_data(df)

Questions about programming?Chat with your personal AI assistant