这有效 p_table.apply(pd.Series.round)
但是它没有小数位
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)
如何将数据框中的所有元素四舍五入到小数点后两位?
[编辑]想通了。
import numpy as np
np.round(p_table, decimals=2)
原文由 Tristan Forward 发布,翻译遵循 CC BY-SA 4.0 许可协议