繁花不似锦
使用np.logical_and + reducelist comprehension或 create helper创建的所有掩码DataFrame和merge:df = pd.DataFrame({ 'A':[1,2,4,1,5,4], 'B':[2,8,9,2,2,3], 'C':[3,3,5,3,1,0],})print (df) A B C0 1 2 31 2 8 32 4 9 53 1 2 34 5 2 15 4 3 0dynamic_cols = ['A','B','C']dynamic_values = [1, 2, 3]m = np.logical_and.reduce([df[a] == b for a, b in (zip(dynamic_cols, dynamic_values))])df1 = df[m]print (df1) A B C0 1 2 33 1 2 3df2 = pd.DataFrame([dynamic_values], columns=dynamic_cols)df1 = df.merge(df2)print (df1) A B C0 1 2 33 1 2 3