+1 vote
in Databases by (7k points)
The elements in the DataFrame are floats. How can I convert them to ints?

1 Answer

0 votes
by (13.5k points)

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
>>>

...