Generation

generate functionThu, 16 Feb 2023

Write a function that loops through the columns in the dataframe and applies try .astype('float64') to them. If a string value is encountered, it will be assigned the value NaN.

def convert_float(dataframe): for c in dataframe.columns: try: dataframe[c] = dataframe[c].astype('float64') except: pass convert_float(dataframe)

Questions about programming?Chat with your personal AI assistant