pandas Python:将列从浮点数转换为整数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43989375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:36:35  来源:igfitidea点击:

Python: Convert column from float to int

pythonpython-2.7pandasnumpydataframe

提问by David Ferris

I am using a pandas, and need to concat two dataframes based on a set_idindex. One of the dataframes has these as floats (see below). How can I convert these to ints?

我正在使用Pandas,需要根据set_id索引连接两个数据帧。其中一个数据帧将这些作为浮点数(见下文)。如何将这些转换为整数?

enter image description here

在此处输入图片说明

回答by EFT

You can do this with

你可以这样做

df.index = df.index.astype(int)