Python 将pandas中的对象数据类型转换为整数

Python 将pandas中的对象数据类型转换为整数,python,pandas,dataframe,type-conversion,Python,Pandas,Dataframe,Type Conversion,我正在尝试转换我的数据集中名为“from_university_number”的一列的数据类型。如果在转换后打印列类型,它将给出int类型,但如果打印整个数据集,它将所有数据类型都作为对象。如何将pandas中的对象数据类型转换为int,以及如何再次检查代码是否工作 df['from_municipality_number'] = df['from_municipality_number'].replace(to_replace='unknown', value='00', inplace=Tr

我正在尝试转换我的数据集中名为“from_university_number”的一列的数据类型。如果在转换后打印列类型,它将给出int类型,但如果打印整个数据集,它将所有数据类型都作为对象。如何将pandas中的对象数据类型转换为int,以及如何再次检查代码是否工作

df['from_municipality_number'] = df['from_municipality_number'].replace(to_replace='unknown', value='00', inplace=True)
df['from_municipality_number'] = df['from_municipality_number'].astype(str).astype(int)       
 
df.dtypes
之后的结果

df['from_municipality_number']=df['from_municipality_number'].astype(str).astype(int) 
       
Name: from_municipality_number, dtype: int64

Outcome after df.dtypes    
    
date                        datetime64[ns]        
from_municipality                   object        
from_municipality_number            object        
to_municipality                     object        
to_municipality_number              object        
count                                int64        
dtype: object
​```

我认为,如果要将它赋给另一个变量,则不必使用
inplace
。试着移除它,然后检查。萨扬,谢谢。成功了。