【发布时间】:2022-01-17 06:54:22
【问题描述】:
我有带有以下示例数据框的大型 CSV:
df1 =
Index Fruit Vegetable
0 Mango Spinach
1 Berry Carrot
2 Banana Cabbage
df2 =
Index Unit Price
0 Mango_123 30
1 234_Artichoke_CE 45
2 23_Banana 12
3 Berry___LE 10
4 Cabbage___12LW 25
5 Rice_ww_12 40
6 Spinach_KJ 34
7 234_Carrot_23 08
8 10000_Lentil 12
9 Pot________12 32
我想替换 df2 中的名称来替换 df1 中的名称以创建以下数据框:
df3=
Index Fruit Vegetable
0 Mango_123 Spinach_KJ
1 Berry___LE 234_Carrot_23
2 23_Banana Cabbage___12LW
执行此操作的通用方法是什么?谢谢。
【问题讨论】:
-
更新:模糊匹配不适用于我的数据集。我会很感激一种使用正则表达式的方法。
标签: python pandas string dataframe merge