In [188]: df
Out[188]:
a b c
0 1.0000 2.2460 2.0000
1 3.0000 4.4920 6.0000
2 5.0000 6.7380 10.0000
In [189]: pd.options.display.float_format = '{:,.2f}'.formatIn [190]: df.apply(lambda x: x.astype(int) if np.allclose(x, x.astype(int)) else x)Out[190]: a b c0 1 2.25 21 3 4.49 62 5 6.74 10更新:
In [222]: dfOut[222]: 0 10 3.0000 5.60001 1.2000 3.4560In [223]: df.applymap(lambda x: str(int(x)) if abs(x - int(x)) < 1e-6 else str(round(x,2)))Out[223]: 0 10 3 5.61 1.2 3.46
注意:请 注意,.applymap()方法的速度非常慢,因为它对
map(func,series)Dataframe中的每个系列都这样做



