【发布时间】:2021-07-14 22:32:26
【问题描述】:
我有一个具有特定 ID 的数据框,我还有一个列表字典。从数据框的 ID 中,如果它存在于字典中,我需要更新该 ID,但在字典中它由两个 ID 更新,以下是示例: 数据框
| ID | Name | Last Name |
|---|---|---|
| 1 | Peter | Smith |
| 2 | John | Allen |
| 7 | Rene | Watson |
| 8 | Dilan | Foster |
字典
Dict = {1: [3, 4], 2: [5, 6], 7: [11], 8:[8]}
预期输出:
| ID | Name | Last Name |
|---|---|---|
| 3 | Peter | Smith |
| 4 | Peter | Smith |
| 5 | John | Allen |
| 6 | John | Allen |
| 11 | Rene | Watson |
| 8 | Dilan | Foster |
提前致谢!
【问题讨论】:
标签: python pandas dataframe dictionary data-science