Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame([(.24, .34), (.02, .70), (.64, .04), (.24, .20)],
                  columns=['deers', 'goats'])
df
Out[2]:
deers goats
0 0.24 0.34
1 0.02 0.70
2 0.64 0.04
3 0.24 0.20

By providing an integer each column is rounded to the same number of decimal places:

In [3]:
df.round(1)
Out[3]:
deers goats
0 0.2 0.3
1 0.0 0.7
2 0.6 0.0
3 0.2 0.2

With a dict, the number of places for specific columns can be specified with the column
names as key and the number of decimal places as value:

In [4]:
df.round({'deers': 1, 'goats': 0})
Out[4]:
deers goats
0 0.2 0.0
1 0.0 1.0
2 0.6 0.0
3 0.2 0.0

Using a Series, the number of places for specific columns can be specified with the column
names as index and the number of decimal places as value:

In [5]:
decimals = pd.Series([0, 1], index=['deers', 'goats'])
df.round(decimals)
Out[5]:
deers goats
0 0.0 0.3
1 0.0 0.7
2 1.0 0.0
3 0.0 0.2