By using the notation df.ColumnName.round()
, you are actually calling pandas.Series.round
, the documentation of which specifies:
decimals : int
Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point.
So you can do:
df = pd.DataFrame({'val':[1,11,130,670]})
df.val.round(decimals=-2)
This produces the output:
0 0
1 0
2 100
3 700
Name: val, dtype: int64
decimals=-3
rounds to the 1000s, and so on. Notably, it also works using pandas.DataFrame.round()
, though the documentation doesn't tell you:
df = pd.DataFrame({'val':[1,11,130,670], 'x':[1,11,150,900]})
df.round({'val':-2})
This will round the column val
to the nearest 100, but leave x
alone.