我是靠谱客的博主 淡然乌龟,这篇文章主要介绍python 列替换_python – Pandas:根据来自另一列的匹配替换列值,现在分享给大家,希望可以做个参考。

我在第一个数据框df1 [“ItemType”]中有一列,如下所示,

Dataframe1

ItemType1

redTomato

whitePotato

yellowPotato

greenCauliflower

yellowCauliflower

yelloSquash

redOnions

YellowOnions

WhiteOnions

yellowCabbage

GreenCabbage

我需要根据从另一个数据框创建的字典替换它.

Dataframe2

ItemType2 newType

whitePotato Potato

yellowPotato Potato

redTomato Tomato

yellowCabbage

GreenCabbage

yellowCauliflower yellowCauliflower

greenCauliflower greenCauliflower

YellowOnions Onions

WhiteOnions Onions

yelloSquash Squash

redOnions Onions

请注意,

>在dataframe2中,某些ItemType与ItemType中的相同

dataframe1.

> dataframe2中的某些ItemType具有nullCabbage等空值.

> dataframe2中的ItemType与dataframe中的ItemType无关

如果相应的Dataframe2 ItemType中的值匹配,我需要替换Dat

最后

以上就是淡然乌龟最近收集整理的关于python 列替换_python – Pandas:根据来自另一列的匹配替换列值的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

相关文章

评论列表共有 0 条评论

立即
投稿
返回
顶部