Home > Mobile >  pandas convert large number to int
pandas convert large number to int

Time:06-22

I import data from a .csv file.

I have a col that contains large number like: 2.950110e 13 but actually the number should be like 29011082602055.

How can I convert it to an integer?

Samples from CSV file

Customer ID      MSISDN National ID
1.08252E 16 2.01121E 11  2.8908E 13

When I change the display settings using pd.set_option('display.float_format', '{:.0f}'.format) numbers change to wrong number with zeros

    MobPay_NID  Billing_National_ID MobPay_Customer_ID
29501100000000       29501100000000  10800100000000000

CodePudding user response:

Try to change data types to int. Look at this code. Change types of choose columns to int or float:

for col in ['COL_NAME1', 'COL_NAME2']:
dfj[col] = dfj[col].astype('int')

CodePudding user response:

From the glimpses we've gotten of your data, it looks like all columns may be integer type. You can try:

df = pd.read_csv('file.csv', dtype='Int64')

But, since I'm still not sure we have the full picture, Could you please run the following and paste the output into your question?

# replace file.csv with your file/path...
with open('file.csv') as f:
    print(f.readline())
    print(f.readline())
    print(f.readline())
  • Related