简体   繁体   English

我们如何将数据框列的数据类型从 object 更改为 python 中的字符串?

[英]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.为了回答铁皮人的评论, 这里是回答所有问题的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何在数据框中的列中的字符串周围添加引号 - How can we add quotes around a string in a column in a data frame 我如何更改 python 中数据框中的列值 - how i can change column values in a data frame in python 如何在 python 中将从字符串中提取的数据的数据类型更改为货币或十进制 - How can I change the data type of data that is being extracted from string to money or decimal in python 我们如何计算数据框列中的重复数据并将结果分配给同一数据框中的新列? - How can we count dupes in a column of a data frame and assign the results to a new column in the same data frame? 我们如何在数据框中的特定列中找到最后一行? - How can we find the last row, in a specific column, in a data frame? 如何将数据从 function 类型更改为 python 中的字符串 - How to change data from a function type into a string in python 列值更改时如何从数据框中提取数据 - How to extract data from data frame when value of column change 当大小/索引不同时,我们如何从另一个数据帧将字段添加到数据帧? - How can we add a field to a data frame, from another data frame, when the sizes/indexes are different? 如何从数据框列中的多行中提取数字和字符串? - How can I extract numbers as well as string from multiple rows in a Data Frame column? 我们如何计算数据框中的项目并将结果分配给数据框中的新列? - How can we do counts of items in a data frame and asign results to a new column in the dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM