簡體   English   中英

使用 float64 的熊貓最大小數位數

[英]pandas maximum number of decimal places using float64

我有一個代碼,我將數據集讀取為字符串以及將其轉換為浮點數的內容。 作為字符串,值是這樣的(單位是埃):

-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 看到的是對象。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM