【发布时间】:2020-07-16 17:48:48
【问题描述】:
我有两个数据框:
df1:
和df2:
我想将df1 中的col1 与df2 中的col_new 匹配。如果它们匹配,那么我想从df1 中提取第一个label。
我想要的输出是:
我正在使用以下代码:
out = (df1.merge(df2, left_on='col1', right_on='col_new'))
但它正在创建更多的记录,因为有多个标签分配给单个值。
【问题讨论】:
-
使用
drop_duplicates删除重复项。 -
收到此错误
AttributeError: 'Series' object has no attribute 'merge'
标签: python python-3.x pandas