w3resource

Pandas DataFrame: round() function

DataFrame - round() function

The round() function is used to round a DataFrame to a variable number of decimal places.

Syntax:

DataFrame.round(self, decimals=0, *args, **kwargs)

Parameters:

Name Description Type/Default Value Required / Optional
decimals  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 decimals is a dict-like, or in the index if decimals is a Series. Any columns not included in decimals will be left as is. Elements of decimals which are not columns of the input will be ignored. int, dict, Series Required
*args

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

  Required
**kwargs    Additional keywords have no effect but might be accepted for compatibility with numpy.
Optional

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

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - rank() function
Next: DataFrame - sum() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/dataframe/dataframe-round.php