这有效p_table.apply(pd.Series.round)
但是它没有小数位
文件说 http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.round.html
import pandas as pd
Series.round(decimals=0, out=None)
我试过这个p_table.apply(pd.Series.round(2))
但出现此错误:
unbound method round() must be called with Series instance as first argument (got int instance instead)
如何将数据框中的所有元素四舍五入到小数点后两位?
Since 0.17.0
你可以做的版本.round(n) https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html
df.round(2)
0 1 2 3
0 0.06 0.67 0.77 0.71
1 0.80 0.56 0.97 0.15
2 0.03 0.59 0.11 0.95
3 0.33 0.19 0.46 0.92
df
0 1 2 3
0 0.057116 0.669422 0.767117 0.708115
1 0.796867 0.557761 0.965837 0.147157
2 0.029647 0.593893 0.114066 0.950810
3 0.325707 0.193619 0.457812 0.920403
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)