我一直在处理从 CSV 导入的数据。 Pandas 将某些列更改为 float ,因此现在这些列中的数字显示为 float !但是,我需要将它们显示为整数或不带逗号。有没有办法将它们转换为整数或不显示逗号?
最佳答案
要修改浮点输出,请执行以下操作:
df= pd.DataFrame(range(5), columns=['a'])
df.a = df.a.astype(float)
df
Out[33]:
a
0 0.0000000
1 1.0000000
2 2.0000000
3 3.0000000
4 4.0000000
pd.options.display.float_format = '{:,.0f}'.format
df
Out[35]:
a
0 0
1 1
2 2
3 3
4 4
https://stackoverflow.com/questions/21291259/