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.sub()
- Python | Pandas Panel.mul()
- Python | Pandas Timestamp.second
- Python | Pandas Series.le()
- Python | Pandas Series.ge()
- Python | Pandas Series.ne()
- Python | Pandas Series.eq()
- Python | Pandas dataframe.add()
- Python | Pandas Panel.abs()
- Python | Pandas Index.contains()
- Python | Pandas DataFrame.abs()
- Python | Pandas Dataframe.iat[ ]
- Python | Pandas Panel.div()
- Python | Pandas Panel.pow()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.