简体   繁体   中英

How can we change data type of a data frame column from object to string in python?

I was taking all categorical variables using

numerical = map_quest._get_numeric_data().columns
categorical = list(set(map_quest.columns) - set(numerical))

Using this, the 'Description' column (which contains description of that particular record) is also getting considered as 'object' which I don't want. I don't want to drop Description either as I would like to use it for later purpose.

Is there any way we can convert 'Description' column to string?

df.astype({"Description": str})

To answer the Tin Man's comment, here are the docs which answer all the questions brought up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM