萧十郎
您可以使用itertools.product生成所有可能的值,然后使用isin:from itertools import productimport pandas as pddata = [['A', 1, 25], ['D', 1, 21], ['C', 2, 32], ['B', 4, 35], ['D', 2, 126], ['B', 1, 3], ['C', 1, 312]]df = pd.DataFrame(data=data, columns=['D_val', 'P_val', 'D_PCode'])list1 = [1, 2]list2 = ['A', 'B', 'C']lookup = set(product(list2, list1))mask = df[['D_val', 'P_val']].apply(tuple, axis=1).isin(lookup)result = df[mask].D_PCodeprint(result)输出0 252 325 36 312Name: D_PCode, dtype: int64或者直接在两列上使用 isin,例如:list1 = [1, 2]list2 = ['A', 'B', 'C']result = df[df.D_val.isin(list2) & df.P_val.isin(list1)].D_PCodeprint(result)输出0 252 325 36 312Name: D_PCode, dtype: int64