Search code examples
pythonpandasscientific-notation

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


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


Solution

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