在Pandas中将浮点数转换为整数? [英] Convert floats to ints in Pandas?

查看:3405
本文介绍了在Pandas中将浮点数转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在处理从CSV导入的数据.熊猫将某些列更改为浮点,因此这些列中的数字现在显示为浮点!但是,我需要将它们显示为整数,或者不显示逗号.有没有办法将它们转换为整数或不显示逗号?

I've been working with data imported from a CSV. Pandas changed some columns to float, so now the numbers in these columns get displayed as floating points! However, I need them to be displayed as integers, or, without comma. Is there a way to convert them to integers or not display the comma?

推荐答案

要修改float输出,请执行以下操作:

To modify the float output do this:

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

这篇关于在Pandas中将浮点数转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆