I have a data frame with 80 columns, for some columns data types should be integers but python sees them as float. Rather than manually changing the data types I am trying to write a loop that identifies the datatype that a column contains and changes the data type accordingly. I have tried the following options but it did not provide any results:
1) I tried to take columns as a variable and if the datatype is float convert it to integer.
for x in data1.columns:
if isinstance(data1.columns,float):
data1[x]=data1[x].astype('int')
2) I also tried this
for x in data1.columns:
if x isinstance(x,float):
data1=data1.astype(int)
else:
break
My general question is is it possible to change column datatypes with a loop, condition, function etc.?
Before posting a question I researched the web, most of the questions about changing individual column's datatype.
Thank you for your answers in advance.