DF1:
NAME LIST_1
BILL ['ZF1', 'ZF2', 'ZF3', 'ZF9', 'ZF11']
PAUL ['ZF1', 'ZF4', 'ZF5', 'ZF2', 'ZF3']
JOHN ['ZF1', 'ZF2', 'ZF5', 'ZF6']
DF2:
ID LIST_2
ZB1 ['ZF1', 'ZF2', 'ZF3']
ZB2 ['ZF1', 'ZF4', 'ZF5']
ZB3 ['ZF2', 'ZF5', 'ZF6']
NEEDED RESULT:
DF1 (Can also be a new DF):
NAME LIST_1 MATCH
BILL ['ZF1', 'ZF2', 'ZF3', 'ZF9', 'ZF11'] ['ZB1']
PAUL ['ZF1', 'ZF4', 'ZF5', 'ZF2', 'ZF3'] ['ZB1', 'ZB2']
JOHN ['ZF1', 'ZF2', 'ZF5', 'ZF6'] ['ZB3']
我还没有真正尝试过很多东西,因为我对列表比较感到困惑。我希望我需要分解DF1和DF2并比较和使用合并?任何帮助都将不胜感激。
2条答案
按热度按时间yduiuuwa1#
尝试:
图纸:
LIST_1
/LIST_2
列中的值是字符串,则将它们转换为列表:ergxz8rk2#
在pandas中处理Series列表总是很棘手。
最合理的方法可能是使用集合运算:
输出: