2

I would like to edit the display precision for a specific dataframe.

Now I saw people stating that you could use something like this:

pd.set_option('precision', 5)

However, how do you make sure that only one specific dataframe uses this precision, and the other remain as they were? Also, is it possible to alter this precision for specific columns only?

Whizkid95
  • 271
  • 4
  • 14
  • what is your data and how do you want to print it? is [this](https://stackoverflow.com/questions/52203304/0-00003-a-value-in-excel-cell-converts-into-3e-05-when-read-in-python-using-pand/52203579#52203579) helpful..? – anky Jan 04 '19 at 07:43

2 Answers2

1

One way is string representation of float column:

np.random.seed(2019)
df = pd.DataFrame(np.random.rand(5,3), columns=list('abc'))
print (df)
          a         b         c
0  0.903482  0.393081  0.623970
1  0.637877  0.880499  0.299172
2  0.702198  0.903206  0.881382
3  0.405750  0.452447  0.267070
4  0.162865  0.889215  0.148476

df['a'] = df['a'].map("{:,.15f}".format)
print (df)
                   a         b         c
0  0.903482214419274  0.393081  0.623970
1  0.637877401022227  0.880499  0.299172
2  0.702198270186552  0.903206  0.881382
3  0.405749797979913  0.452447  0.267070
4  0.162864870291925  0.889215  0.148476

print (df.dtypes)
a     object
b    float64
c    float64
dtype: object
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
0

This method will not affect the original dataframe.
df.style.set_precision(5)

For One column you can use
df.style.format({'Column_Name': "{:.5f}"})