Q:

how to set the number to become 4 decimal places

I have this code
    tableyy = final.style.apply(color, axis=None).set_table_attributes('border="" class = "dataframe table table-hover table-bordered"').set_precision(4).render()

set_precision(4) I wish to make it my value to become 4 decimal places, but for some value still return me 5 decimal places for example 0.03045.  So anyone can share me how to replace the set_precision so that my value all return in 4 decimal places but not 4 significant value. 

A:

You want to look into the DataFrame.round(decimals=0, *args, **kwargs) method.   I think the following code sample would do what you are asking:
tableyy = final.round(4).style.apply(
  color, axis=None
).set_table_attributes(
  'border="" class = "dataframe table table-hover table-bordered"'
).render()

Here is some code I used to test this:
import pandas as pd
import numpy as np

df = pd. DataFrame(
  np.random.random([3,3]), 
  columns=['A', 'B', 'C'], 
  index=['first', 'second', 'third']
)

table = df.round(2).style.applymap(
  lambda val: 'color: red' if val > 0.5 else 'color: black'
).set_table_attributes(
  'border="" class = "dataframe table table-hover table-border:red"'
).render()

with open('test.html', 'w+') as f:
  f.write(table)

Then opening the resulting test.html file in the browser shows a table where each column has at most 2 decimal places for me.