I want to use pandas style, and to use comma as decimal separator.
Take this dataframe for example:
tb = pd.DataFrame({"Variable": [5, 4.5, 4.8, 4.7], "std_err": [1, .06, .09, .17]},
index = ['Group A', 'Group B', 'Group C', 'Group D'])
Variable | std_err | |
---|---|---|
Group A | 5.0 | 1.00 |
Group B | 4.5 | 0.06 |
Group C | 4.8 | 0.09 |
Group D | 4.7 | 0.17 |
I tried this:
locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
pd.set_option("float_format", locale.str)
tb = pd.DataFrame({"Variable": [4.9853, 4.5345, 4.8542, 4.7234],
"std_err": [.9234, .0676, .0917, .1784]},
index = ['Group A', 'Group B', 'Group C', 'Group D'])
tb.style.bar()
But I expected to see commas as decimal separators and the style bars, rather I've got this a table formatted with style, but with locale ignored.
Can I have both? The table formatted with style (bars, colors etc) and with commas as decimal separators?
CodePudding user response:
The most straightforward fix is to specify the decimal
parameter of
Other alternatives include setting the formatter
to a function like