Pandas: convert dtype 'object' to int

后端 未结 8 2011
南旧
南旧 2020-11-29 02:02

I\'ve read an SQL query into Pandas and the values are coming in as dtype \'object\', although they are strings, dates and integers. I am able to convert the date \'object\'

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 02:21

    My train data contains three features are object after applying astype it converts the object into numeric but before that, you need to perform some preprocessing steps:

    train.dtypes
    
    C12       object
    C13       object
    C14       Object
    
    train['C14'] = train.C14.astype(int)
    
    train.dtypes
    
    C12       object
    C13       object
    C14       int32
    

提交回复
热议问题