rPython is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.round() function is used to round a DataFrame to a variable number of decimal places. This function provides the flexibility to round different columns by different places.
Syntax:DataFrame.round(decimals=0, *args, **kwargs)
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.
Returns : DataFrame object
Example #1: Use
round() function to round off all columns in the dataframe to 3 decimal places
Note : We need to populate our dataframe with decimal values. Let’s use numpy random function to achieve the task.
Lets use the
dataframe.round() function to round off all the decimal values in the dataframe to 3 decimal places.
Example #2: Use
round() function to round off all the columns in dataframe to different places.
Lets perform round off each column to different places
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course