我有两个数据帧df1和df2
df1
index emp_id name code
0 07 emp07 'A'
1 11 emp11 'B'
2 30 emp30 'C'
df2
index emp_id salary
0 06 1000
1 17 2000
2 11 3000
我想存储从df1['emp_id']
到df2.index
的映射
示例:输入数组-['emp11','B'](来自df1)
预期输出:[11, 2] # this is df1['emp_id'], df2.index
我正在尝试的代码:
columns_to_idx = {emp_id: i for i, emp_id in
enumerate(list(DF1.set_index('emp_id').loc[DF2.index][['name', 'code']]))}
我认为您需要^{} 与内部联接,以及^{} 作为索引中的列,以避免丢失它:
然后可以创建
MultiIndex
并按元组选择:相关问题 更多 >
编程相关推荐