pandas 1.4.2

ParametersReturnsBackRef
round(self, decimals: 'int | dict[IndexLabel, int] | Series' = 0, *args, **kwargs) -> 'DataFrame'

Parameters

decimals : int, dict, Series

Number of decimal places to round each column to. If an int is given, round each column to the same number of places. Otherwise dict and Series round to variable numbers of places. Column names should be in the keys if :None:None:`decimals` is a dict-like, or in the index if :None:None:`decimals` is a Series. Any columns not included in :None:None:`decimals` will be left as is. Elements of :None:None:`decimals` which are not columns of the input will be ignored.

*args :

Additional keywords have no effect but might be accepted for compatibility with numpy.

**kwargs :

Additional keywords have no effect but might be accepted for compatibility with numpy.

Returns

DataFrame

A DataFrame with the affected columns rounded to the specified number of decimal places.

Round a DataFrame to a variable number of decimal places.

See Also

Series.round

Round a Series to the given number of decimals.

numpy.around

Round a numpy array to the given number of decimals.

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame([(.21, .32), (.01, .67), (.66, .03), (.21, .18)],
...  columns=['dogs', 'cats'])
... df dogs cats 0 0.21 0.32 1 0.01 0.67 2 0.66 0.03 3 0.21 0.18

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

This example is valid syntax, but we were not able to check execution
>>> df.round(1)
    dogs  cats
0   0.2   0.3
1   0.0   0.7
2   0.7   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

This example is valid syntax, but we were not able to check execution
>>> df.round({'dogs': 1, 'cats': 0})
    dogs  cats
0   0.2   0.0
1   0.0   1.0
2   0.7   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

This example is valid syntax, but we were not able to check execution
>>> decimals = pd.Series([0, 1], index=['cats', 'dogs'])
... df.round(decimals) dogs cats 0 0.2 0.0 1 0.0 1.0 2 0.7 0.0 3 0.2 0.0
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.arrays.numeric.NumericArray.round pandas.core.series.Series.round

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#9361
type: <class 'function'>
Commit: