溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用pandas怎么精度處理小數(shù)位數(shù)

發(fā)布時間:2021-05-20 15:34:17 來源:億速云 閱讀:883 作者:Leah 欄目:開發(fā)技術

這篇文章給大家介紹使用pandas怎么精度處理小數(shù)位數(shù),內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

控制臺打印時顯示的2位小數(shù):

pd.set_option('precision', 2)

實際修改數(shù)據(jù)精度:

官例:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html

>>> df = pd.DataFrame(np.random.random([3, 3]),
...  columns=['A', 'B', 'C'], index=['first', 'second', 'third'])
>>> df
    A   B   C
first 0.028208 0.992815 0.173891
second 0.038683 0.645646 0.577595
third 0.877076 0.149370 0.491027
>>> df.round(2)
   A  B  C
first 0.03 0.99 0.17
second 0.04 0.65 0.58
third 0.88 0.15 0.49
>>> df.round({'A': 1, 'C': 2})
   A   B  C
first 0.0 0.992815 0.17
second 0.0 0.645646 0.58
third 0.9 0.149370 0.49
>>> decimals = pd.Series([1, 0, 2], index=['A', 'B', 'C'])
>>> df.round(decimals)
   A B  C
first 0.0 1 0.17
second 0.0 1 0.58
third 0.9 0 0.49

關于使用pandas怎么精度處理小數(shù)位數(shù)就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI