There is a df Pandas dataframe: id member_id loan_amnt funded_amnt funded_amnt_inv term int_rate installment grade sub_grade 0 1077501 1296599 5000 5000 4975 36 months 10.65% 162.87 B B2 ... Computer 27.65 0.0 735.0 739.0 1.0 3.0 13648.0 83.7% 9.0 1 1077430 1314167 2500 2500 2500 60 months 15.27% 59.83 C C4 ... bike 1.00 0.0 740.0 744.0 5.0 3.0 1687.0 9.4% 4.0 Write a function that will loop through all the column names in this dataframe and apply try .astype('Int64') to them. In case of an error the function should just execute pass
def try_to_int(df): for col in df.columns: try: df[col] = df[col].astype('Int64') except: pass