简体   繁体   English

用另一列中的值替换pandas列中的值

[英]Replacing pandas column value with values from another column

I have a Dataframe like so, lets say x: 我有一个这样的数据框,让我们说x:

enter image description here 在此处输入图片说明

And there is another dataframe with descriptions for the labelNames like so, lets say y: 还有另一个数据框,其中包含对labelNames的描述,就像这样,假设y:

enter image description here 在此处输入图片说明

Now, How do I replace the LabelNames in the x with the description in the y? 现在,如何将x中的LabelNames替换为y中的描述? Know that LabelNames in x is not unique 知道x中的LabelNames不是唯一的

You can use index matching: 您可以使用索引匹配:

x = x.set_index('LabelName')
y = y.set_index('LabelName')

Then 然后

x['Description'] = y.ClassDescription

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

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