Pandas - read_csv 科学记数法大数 [英] Pandas - read_csv scientific notation large number

查看:154
本文介绍了Pandas - read_csv 科学记数法大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Pandas 读取一个 csv 文件,其中一些行采用科学记数法.

I am trying to read a csv file with pandas that has some rows in scientific notation.

当它读取值时,它没有捕获真正的底层数字.当我重新利用数据时,真正的价值就会丢失.

When it reads the values it is not capturing the true underlying number. When I re-purpose the data the true value gets lost.

df = pd.read_csv('0_IDI_Submitter_out.csv')

我试图保留的基本真实值如下:

The underlying true values that I am trying to preserve are as follows:

      INPUT: Extra 1
0     8921107
1     56300839420000
2     56207557000000

然而,pandas 将其读作

However, pandas reads it as

 INPUT: Extra 1
0     8921107
1     5.63008E+13
2     5.62076E+13

如果我尝试编写新的 csv 或使用此数据,则值显示为:

If I try to write a new csv or use this data the values show as:

 INPUT: Extra 1
0     8921107
1     56300800000000
2     56207600000000

如何让 Pandas 读取真实数字而不是导致其错误转换的科学计数法?

How can I get pandas to read the true number rather than the scientific notation which causes it to convert incorrectly?

推荐答案

似乎无法重现您的问题,但也许这行得通?

Can't seem to reproduce your problem, but maybe this will work?

df = pd.read_csv('0_IDI_Submitter_out.csv', dtype={'INPUT: Extra 1':np.object_})

另外,检查数据帧的 dtypes:

Also, check the dtypes of your dataframe:

result = df.dtypes
print(result)

这篇关于Pandas - read_csv 科学记数法大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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