Generation

generate functionMon, 13 Feb 2023

There is Pandas dataframe: surgery age rectal_temp pulse respiratory_rate extremities_temp pain outcome 0 38.50 66 3 3 ? 2 ? 0 1 39.2 88 ? ? 4 1 ? 0 2 38.30 40 1 1 3 1 ? 0 3 39.10 164 4 1 6 2 1 0 4 37.30 104 ? ? 6 2 ? 0 Write a function that will try to change the Dtype of all columns to float. If this fails, then except pass

def change_dtype(df): for col in df.columns: try: df[col] = df[col].astype(float) except: pass return df df = change_dtype(df)

Questions about programming?Chat with your personal AI assistant