Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python df类型不会永久更改为int_Python_Jupyter - Fatal编程技术网

Python df类型不会永久更改为int

Python df类型不会永久更改为int,python,jupyter,Python,Jupyter,很抱歉再次提出问题,但这对我来说毫无意义 我正在尝试将列的数据类型更改为int,并执行了以下操作: df.Age.astype(object).astype(int) 这是可行的,看起来它变成了int,但如果我这样做了 df.Age 然后它将显示为对象数据类型?如何使更改永久化?您必须分配系列: df.Age = df.Age.astype(int) 还考虑: df["Age"] = pd.to_numeric(df["Age"]) 参考资料:您必须使用序列号分配: df.Age =

很抱歉再次提出问题,但这对我来说毫无意义

我正在尝试将列的数据类型更改为int,并执行了以下操作:

df.Age.astype(object).astype(int)
这是可行的,看起来它变成了int,但如果我这样做了

df.Age 

然后它将显示为对象数据类型?如何使更改永久化?

您必须分配系列:

df.Age = df.Age.astype(int)
还考虑:

df["Age"] = pd.to_numeric(df["Age"])

参考资料:

您必须使用序列号分配:

df.Age = df.Age.astype(int)
还考虑:

df["Age"] = pd.to_numeric(df["Age"])

参考资料:

为什么
astype(object).astype(int)
?为什么不直接
.astype(int)
呢?@DeepSpace astype(object)。astype是我在尝试使用它时读到的东西out@drec4s是的,确实如此,我现在可以看到我错在哪里了,这要感谢Bobbawhy
astype(object)。astype(int)
?为什么不直接
.astype(int)
呢?@DeepSpace astype(object)。astype是我在尝试使用它时读到的东西out@drec4s是的,确实如此,我现在可以看到我错在哪里了,多亏了贿赂银行你的回答,这让它起作用了,而且aystype的方式就是我在网上读到的。我从来没见过to_数字方式谢谢你,这让它起作用了,aystype方式就是我在网上读到的。从来没有见过真正的数字方式