Integers from excel files become floats?
Excel treats all numbers as floats. In general, it doesn't care whether your_number % 1 == 0.0
is true or not.
Example: A1 = 63.0, B1 = 63, C1 = INT(A1), A2 = TYPE(A1), B2 = TYPE(B1), C2 = TYPE(C1)
You'l see that TYPE()
returns 1 in each case.
From the Excel Help:
If value is TYPE returns
Number 1
Text 2
Logical value 4
Error value 16
Array 64
xlrd
reports what it finds. xlrd
doesn't mangle its input before exposing it to you. Converting a column from (62.9, 63.0, 63.1, etc)
to (62.9, 63, 63.1, etc)
would seem like a pointless waste of CPU time to me.
Looking at the different cell types in the documentation, it seems that there isn't any integer type for cells, they're just floats. Hence, that's the reason you're getting floats back even when you wrote an integer.
To convert a float to an integer just use int
:
>>> int(63.0)
63
>>> int(sheet.row(1)[0].value)
63
The answer given by jcollado is alright if you have all the entries in the excel sheet as numbers which are integers. But suppose you have a number which is a float you can always put a check condition like -
if i==int(i): //checking for the integer:
print int(i) // solving your problem and printing the integer
else:
print i //printing the float if present
Hope you find this useful :)