How To Round Values Only For Display In Pandas While Retaining Original Ones In The Dataframe?
I wish to only round values in the DataFrame for display purposes, when I use head() or tail() but I want the DataFrame to retain the original values. I tried using the round metho
Solution 1:
You can temporarily change the display option:
with pd.option_context('precision', 3):
print(df.head())
012340 -0.462 -0.698 -2.0300.766 -1.67010.9250.603 -1.0621.026 -0.09620.5890.819 -1.040 -0.1622.4673 -1.1690.637 -0.4350.5841.2324 -0.704 -0.6231.2260.5070.507
Or change it permanently:
pd.set_option('precision', 3)
A simple print(df.head().round(3))
would also work in this case. They will not change the DataFrame in place.
Post a Comment for "How To Round Values Only For Display In Pandas While Retaining Original Ones In The Dataframe?"