1、针对两个数据集,有共同的字段“工号”,根据Money_Stand_Data数据集中工号和性别,匹配Pay_Data数据集对应工号的性别,具体如下:
dict_1 = dict(zip(Money_Stand_Data['工号'], Money_Stand_Data['性别'])) Pay_Data['性别'] = Pay_Data['工号'].map(dict_1)
2、针对两个数据集,有共同的字段“工号”,根据Money_Stand_Data数据集中工号、a、b,匹配Pay_Data数据集对应工号的A、B,具体如下:
Keys_1 = ['a', 'b'] # Money_Stand_Data 数据集 Values_1 = ['A', 'B'] # Pay_Data数据集 Dictionary_1 = dict(zip(Keys_1, Values_1)) for k,v in Dictionary_1.items(): dict_1 = dict(zip(Money_Stand_Data['工号'], Money_Stand_Data[k])) Pay_Data[v] = Pay_Data['工号'].map(dict_1 )
|