在数据框列中禁止科学格式 [英] Suppress Scientific Format in a Dataframe Column

查看:73
本文介绍了在数据框列中禁止科学格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在熊猫数据框中有一个名为accountnumber的列,其值类似于4.11889000e + 11.我想取消科学计数法并将其值转换为4118890000.我尝试了以下方法,但是没有用.

I have a column called accountnumber with values similar to 4.11889000e+11 in a pandas dataframe. I want to suppress the scientific notation and convert the values to 4118890000. I have tried the following method and did not work.

df = pd.read_csv(data.csv)
pd.options.display.float_format = '{:,.3f}'.format

请推荐.

推荐答案

我假设帐号的指数表示法必须来自数据文件.如果我用完整的帐号创建一个小的csv,熊猫会将它们解释为整数.

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')

但是,如果csv中的帐号以指数符号表示,则熊猫会将其读取为浮点数.

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')

您有2个选择.首先,更正创建csv的过程,以便正确地写出帐号.第二种是将acct_num列的数据类型更改为整数.

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

这篇关于在数据框列中禁止科学格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆