maxframe.dataframe.DataFrame.round#
- DataFrame.round(decimals=0, *args, **kwargs)#
将 DataFrame 四舍五入到可变的小数位数。
- 参数:
- 返回:
一个 DataFrame,其中受影响的列已四舍五入到指定的小数位数。
- 返回类型:
参见
numpy.around将 numpy 数组四舍五入到给定的小数位数。
Series.round将 Series 四舍五入到给定的小数位数。
示例
>>> import maxframe.dataframe as md >>> df = md.DataFrame([(.21, .32), (.01, .67), (.66, .03), (.21, .18)], ... columns=['dogs', 'cats']) >>> df.execute() dogs cats 0 0.21 0.32 1 0.01 0.67 2 0.66 0.03 3 0.21 0.18
通过提供一个整数,每个列都会四舍五入到相同的小数位数
>>> df.round(1).execute() dogs cats 0 0.2 0.3 1 0.0 0.7 2 0.7 0.0 3 0.2 0.2
通过提供一个字典,可以为特定列指定小数位数,其中键是列名,值是小数位数
>>> df.round({'dogs': 1, 'cats': 0}).execute() dogs cats 0 0.2 0.0 1 0.0 1.0 2 0.7 0.0 3 0.2 0.0