+2 votes
in Databases by (73.2k points)
The elements in the DataFrame are floats. How can I convert them to ints?

1 Answer

+1 vote
by (346k points)
selected by
 
Best answer

Use astype(int) to convert them to ints.

E.g.

>>> df = pd.DataFrame([[1.5, 2.6,3.7],[2.5,3.6,4.1],[4.1,5.2,6.5]], columns=list('ABC'))
>>> df
     A    B    C
0  1.5  2.6  3.7
1  2.5  3.6  4.1
2  4.1  5.2  6.5
>>> df.astype(int)
   A  B  C
0  1  2  3
1  2  3  4
2  4  5  6
>>>


...