bigframes.pandas.DataFrame.round#

DataFrame.round(decimals:int|dict[Hashable,int]=0)DataFrame[source]#

Round a DataFrame to a variable number of decimal places.

Examples:

>>>importbigframes.pandasasbpd>>>df=bpd.DataFrame([(.21,.32),(.01,.67),(.66,.03),(.21,.18)],...columns=['dogs','cats'])>>>df   dogs  cats0  0.21  0.321  0.01  0.672  0.66  0.033  0.21  0.18[4 rows x 2 columns]

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

>>>df.round(1)    dogs  cats0   0.2   0.31   0.0   0.72   0.7   0.03   0.2   0.2[4 rows x 2 columns]

With a dict, the number of places for specific columns can bespecified with the column names as key and the number of decimalplaces as value

>>>df.round({'dogs':1,'cats':0})    dogs  cats0   0.2   0.01   0.0   1.02   0.7   0.03   0.2   0.0[4 rows x 2 columns]

Using a Series, the number of places for specific columns can bespecified with the column names as index and the number ofdecimal places as value

>>>decimals=pd.Series([0,1],index=['cats','dogs'])>>>df.round(decimals)    dogs  cats0   0.2   0.01   0.0   1.02   0.7   0.03   0.2   0.0[4 rows x 2 columns]
Parameters:

decimals (int,dict,Series) – Number of decimal places to round each column to. If an int isgiven, 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 ifdecimals is adict-like, or in the index ifdecimals is a Series. Anycolumns not included indecimals will be left as is. Elementsofdecimals which are not columns of the input will beignored.

Returns:

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

Return type:

bigframes.pandas.DataFrame

On this page

This Page