when using pd.Style.Bar, pandas converts my data to 6 decimals. Can anybody help me ?
Example :
JavaScript
x
6
1
import pandas as pd
2
data = [[0.02, 0.04],[0.06, 0.07]]
3
dt = pd.DataFrame(data)
4
5
a = dt.style.bar(align = 'mid', color = ['lightblue', 'red'])
6
or even trying :
JavaScript
1
3
1
a = (dt.style.bar(align = 'mid', color = ['lightblue', 'red'])
2
.applymap('{:,.2f}'.format))
3
Both give me the following output (with the column bars – sorry I can’t copy here) :
JavaScript
1
4
1
0 1
2
0 0.020000 0.040000
3
1 0.060000 0.070000
4
Advertisement
Answer
If you just want to ensure that the precision of a
is 2
, you could call pandas.io.formats.style.Styler.set_precision
when defining a
.
Example
JavaScript
1
6
1
import pandas as pd
2
3
data = [[0.02, 0.04],[0.06, 0.07]]
4
dt = pd.DataFrame(data)
5
a = dt.style.bar(align = 'mid', color = ['lightblue', 'red']).set_precision(2)
6
a
JavaScript
1
4
1
0 1
2
0 0.02 0.04
3
1 0.06 0.07
4