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

使用字典替换pandas列中字符串中的字符串

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

使用字典替换pandas列中字符串中的字符串

您可以创建

dictionary
然后
replace

ids = {'Id':['NYC','LA','UK'],      'City':['New York City','Los Angeles','United Kingdom']}ids = dict(zip(ids['Id'], ids['City']))print (ids){'UK': 'United Kingdom', 'LA': 'Los Angeles', 'NYC': 'New York City'}df['commentTest'] = df['Comment'].replace(ids, regex=True)print (df)  Categories Comment  Type       animal      The NYC tree is very big  tree   1      plant  The cat from the UK is small   dog   2     object     The rock was found in LA.  rock          commentTest  0        The New York City tree is very big  1  The cat from the United Kingdom is small  2        The rock was found in Los Angeles.


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

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

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