A method available from pandas version 2.0. is "convert_dtypes", which will find the best type match for the data. So as you posted in the question this will take care of objects converted to float or integer if that matches the column data.
df = df.convert_dtypes()