【发布时间】:2021-08-22 22:07:12
【问题描述】:
目前,我有两个如下所示的数据框:
DF1:
| Date | Country | A | B | C |
|---|---|---|---|---|
| 01/01/2020 | The United States | 0 | 1 | 5 |
| 01/02/2020 | The United States | 2 | 5 | 0 |
| 01/03/2020 | The United States | 1 | 4 | 1 |
| ... | ... | ... | ... | ... |
| 01/01/2020 | Republic of Korea | 2 | 3 | 7 |
| 01/02/2020 | Republic of Korea | 4 | 5 | 6 |
和 DF2:
| Date | Country | D |
|---|---|---|
| 01/01/2020 | United States of America | 9.0 |
| 01/02/2020 | United States of America | 9.1 |
| 01/03/2020 | United States of America | 9.4 |
| ... | ... | ... |
| 01/01/2020 | South Korea | 2.1 |
| 01/02/2020 | South Korea | 2.5 |
我想将它们合并到 'Country' 和 'Date_reported' 但它们用于每个国家/地区的名称可能完全不同。我已经研究了fuzzywuzzy 和其他一些软件包,但我找不到一个可以让我完全按照我想要的方式进行合并的命令。我希望最终得到以下数据框(使用 DF1 的国家/地区名称):
| Date | Country | A | B | C | D |
|---|---|---|---|---|---|
| 01/01/2020 | The United States | 0 | 1 | 5 | 9.0 |
| 01/02/2020 | The United States | 2 | 5 | 0 | 9.1 |
| 01/03/2020 | The United States | 1 | 4 | 1 | 9.4 |
| ... | ... | ... | ... | ... | ... |
| 01/01/2020 | Republic of Korea | 2 | 3 | 7 | 2.1 |
| 01/02/2020 | Republic of Korea | 4 | 5 | 6 | 2.5 |
有没有一种不需要我手动切换所有 DF2 国家/地区名称的有效方法?感谢您在这个主题上给我的任何帮助。
【问题讨论】:
标签: python pandas dataframe merge fuzzywuzzy