Suppress Scientific Format in a Dataframe Column

半腔热情 提交于 2019-12-05 02:37:47

I assume the exponential notation for the account numbers must come from the data file. If I create a small csv with the full account numbers, pandas will interpret them as integers.

     acct_num
0  4118890000
1  9876543210

df['acct_num'].dtype
Out[51]: dtype('int64')

However, if the account numbers in the csv are represented in exponential notation then pandas will read them as floats.

       acct_num
0  4.118890e+11
1  9.876543e+11

df['acct_num'].dtype
Out[54]: dtype('float64')

You have 2 options. First, correct the process that creates the csv so the account numbers are written out correctly. The second is to change the data type of the acct_num column to integer.

df['acct_num'] = df['acct_num'].astype('int64')

df
Out[66]: 
       acct_num
0  411889000000
1  987654321000

You don't need the thousand separators "," and the 3 decimals for the account numbers.

Use the following instead.

pd.options.display.float_format = '{:.0f}'.format
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!