[英]How to get the filtered dataframe for calculations while retaining the original one in pandas?
[英]How to round values only for display in pandas while retaining original ones in the dataframe?
我希望只在數據框中舍入值以用於顯示目的,當我使用head()或tail()時,我希望數據幀保留原始值。
我嘗試使用圓方法,但它更改了原始數據框中的值。 我不希望每次都為此創建一個單獨的副本。
除了創建單獨的副本之外還有其他方法嗎?
編輯:我無法瀏覽值,因為有些列有e ^ 10符號。 我只想看看最多兩到三個小數位,而不是一直看着指數值。
編輯2:解決了。 感謝您及時的回復。
您可以暫時更改顯示選項:
with pd.option_context('precision', 3):
print(df.head())
0 1 2 3 4
0 -0.462 -0.698 -2.030 0.766 -1.670
1 0.925 0.603 -1.062 1.026 -0.096
2 0.589 0.819 -1.040 -0.162 2.467
3 -1.169 0.637 -0.435 0.584 1.232
4 -0.704 -0.623 1.226 0.507 0.507
或永久更改:
pd.set_option('precision', 3)
在這種情況下,簡單的print(df.head().round(3))
也適用。 他們不會更改DataFrame。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.