Home > Net >  How do I convert a float datatype column, displayed in e notation format, to integer in Pandas?
How do I convert a float datatype column, displayed in e notation format, to integer in Pandas?

Time:08-07

This is the column, , and when i try med_app['patient_id'].astype(int) it results in a negative output like so, . I want the output in this format; 2.987250e 13 to 29872499824296

CodePudding user response:

The max size int32 is 2**31 - 1 = 2147483647 ≈ 2.147e9. If you want ints larger than this, you should use int64, which has max size 2**63 - 1 = 9223372036854775807 ≈ 9.2233e 18. When I test this myself, it automatically chooses int64 when I perform .astype(int), but you can be explicit and do .astype(np.int64) (when you import numpy as np). If you need to go even larger, you can use uint64, which goes all the way up to 2 ** 64 ≈ 1.845e 19.

CodePudding user response:

I think if you check the type of column without any type conversion the column would still be of type int, what you are seeing is just the pandas display format which by default uses scientific notation for extremely large/small numbers.

If you wish to visualise the numbers as stored then you just need to set appropriate pandas display option.

med_app[["patient_id"]].style.format("{:.0f}")

  • Related