熊猫使用float64的最大小数位数

时间:2019-02-01 18:00:54

标签: python pandas decimal

我有一个代码,其中我将数据集读取为字符串,然后将其转换为浮点数。作为字符串,值是这样的(单位为埃):

-11.22221784

当我现在通过以下方式进行隐藏时:

cols=[....a list of columns i want to convert]

for col in cols:
    df[col] = df[col].astype(float)

该值将四舍五入为:

-11.222218

我不想要的! 如果我通过

进行转换
....
import decimal as D

for col in cols:
    df[col] = df[col].astype(D.Decimal)

我在数据框中获得了正确的值,但是我无法绘制数据,因为dtype panas看到的是对象。

1 个答案:

答案 0 :(得分:1)

Pandas将列显示为小数点后6位,并正确存储了该列:

In [11]: pd.Series([-11.22221784])
Out[11]:
0   -11.222218
dtype: float64

In [12]: pd.Series([-11.22221784])[0]
Out[12]: -11.22221784
相关问题