Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/core/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ class Styler(object):
{% for c in r %}
<{{c.type}} id="T_{{uuid}}{{c.id}}" class="{{c.class}}">
{% if c.value is number %}
{{c.value|round(precision)}}
{% if precision %}
{{c.value|round(precision)}}
{% else %}
{{'%.0f'|format(c.value)}}
{% endif %}
{% else %}
{{c.value}}
{% endif %}
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ def test_precision(self):
self.assertTrue(s is s2)
self.assertEqual(s.precision, 4)

def test_precision_zero(self):
df = pd.DataFrame({'A': 100, 'B': [0, 1, 2, 3, np.nan]})
df['C'] = df['A'] / df['B']
result = df.style.set_precision(0).render()
self.assertEqual(result.count('.'), 0)

def test_apply_none(self):
def f(x):
return pd.DataFrame(np.where(x == x.max(), 'color: red', ''),
Expand Down