我有一个dataframedf1,比如下面的一个标签列表
tags
0 label
0 document
0 text
0 paper
0 poster
...
21600 wood
21600 hot tub
21600 tub
21600 terrace
21600 blossom
还有另一个数据帧df2,它映射到df中存在的标记,并映射到列名“name”
name iab
0 abies Nature and Wildlife
1 absinthe Food & Drink
2 abyssinian Pets
3 accessories Style & Fashion
4 accessory Style & Fashion
... ... ... ... ...
1595 rows × 4 columns
本质上,其思想是搜索df2中与df1中的标记相对应的列“name”,以找到相应的“iab”映射,并输出一个包含两列的CSV—标记及其对应的“iab”映射
输出如下所示:
tags iab
0 label <corresponding iab mapping
to 'name' found in df2>
0 document
0 text
0 paper
0 poster
...
21600 wood
21600 hot tub
21600 tub
21600 terrace
21600 blossom
我需要帮助来实现这一目标。提前谢谢你
注:
我试过的是
df_iab[df_iab['name'].isin(df['image_CONTAINS_OBJECT'])]
但这只会将df2减少到与“标签”匹配的“iab”,而不会真正执行搜索并映射找到的值
合并:
另一种方法是使用
.map
将iab
细节从df2
传输到df1
它的工作原理
相关问题 更多 >
编程相关推荐