Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas Excel Read - Integer column converted to Float while looping

After reading excel file using pandas, i am validating the "Numberss" column is having only the Integer values. If any other value is present i am displaying error message.

When i loop through the column items the values are converted to float automatically

for index, item in self.df["Numberss"].items():
     print(item)

If my input column is

5, 5.65, 5.55, 6

print(item) output is as:

5.0, 5.65, 5.55, 6.0

instead of

5, 5.65, 5.55, 6
like image 934
useruser00 Avatar asked Dec 21 '25 21:12

useruser00


1 Answers

It is because your column contains integer and null values. Pandas reads these null values as NaN which is internally stored as a float.

You will have to replace these NaN values with a integer value, if you want to the column type as int

like image 128
Ronak Mutha Avatar answered Dec 24 '25 10:12

Ronak Mutha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!