您可以创建
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.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)