Python 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.
When doing mathematical operations on series, many times the returned series is having decimal values and decimal values could go to upto many places. Pandas
Series.round() method is used in such cases only to round of decimal values in series.
Syntax: Series.round(decimals=0, *args, **kwargs)
decimals: Int value, specifies upto what number of decimal places the value should be rounded of, default is 0.
Return type: Series with updated values
To download the data set used in following example, click here.
In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.
Since in the dataframe, there isn’t any series with decimal values more than 1 place. Hence the Salary column is divided by the Weight column first to get a series with decimal values. Since the returned series is having values with decimal upto 6 places. First a new series created by using
round() method and another series new2 is created by passing a parameter of 2 to
round() method to see working of this method. Before doing any operations, null rows were removed using
As shown in the Output image, the new series is completely rounded of with no decimal values and new2 series contains decimals upto 2 places after that only.
- Python | pandas.map()
- Python | Pandas Panel.sum()
- Python | Pandas Index.contains()
- Python | Pandas DataFrame.abs()
- Python | Pandas PeriodIndex.second
- Python | Pandas.to_datetime()
- Python | Pandas Series.between()
- Python | Pandas DataFrame.where()
- Python | Pandas Panel.abs()
- Python | Pandas dataframe.add()
- Python | Pandas dataframe.div()
- Python | Pandas Series.agg()
- Python | Pandas dataframe.mean()
- Python | Pandas dataframe.max()
- Python | Pandas dataframe.mad()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.