pandas数据框有两列,其中包含需要获取ID的ID列表,S不在其他列中
SaveFileDialog
答案 0 :(得分:1)
将值转换为集合并获得差值:
df['Column_3'] = [list(set(y).difference(x)) for x, y in zip(df['Column_1'], df['Column_2'])]
print (df)
id Column_1 Column_2 Column_3
0 1 [1, 2, 7] [1, 2, 5, 7, 9] [9, 5]
1 2 [4, 8, 2, 7] [4, 8, 2, 7] []
2 3 [5, 7, 2, 9] [9] []
3 4 [4, 7, 2, 9] [3] [3]