栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从熊猫数据帧将字符串数组(类别)转换为int数组

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从熊猫数据帧将字符串数组(类别)转换为int数组

如果您有一个字符串向量或其他对象的向量,并且想要为其提供分类标签,则可以使用

Factor
该类(在
pandas
名称空间中可用):

In [1]: s = Series(['single', 'touching', 'nuclei', 'dusts', 'touching', 'single', 'nuclei'])In [2]: sOut[2]: 0    single1    touching2    nuclei3    dusts4    touching5    single6    nucleiName: None, Length: 7In [4]: Factor(s)Out[4]: Factor:array([single, touching, nuclei, dusts, touching, single, nuclei], dtype=object)Levels (4): [dusts nuclei single touching]

该因素有属性

labels
levels

In [7]: f = Factor(s)In [8]: f.labelsOut[8]: array([2, 3, 1, 0, 3, 2, 1], dtype=int32)In [9]: f.levelsOut[9]: Index([dusts, nuclei, single, touching], dtype=object)

这是针对一维矢量的,因此不确定是否可以立即将其应用于您的问题,但请看一下。

顺便说一句,我建议您在statsmodels和/或scikit-learn邮件列表上问这些问题,因为我们大多数人都不是SO用户。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/653106.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号