For循环在pandas dataframe列



例如,我有2个数据帧,3列,我想做

a = df[x].isin(df2[x])
b = df[x].isin(df2[y])
c = df[y].isin(df2[x])
d = df[y].isin(df2[x])

x和y是我的两个数据框的列名。我如何在循环中执行并保存每个结果?所以它可以很优雅。结果和我预期的差不多:

a; True = ddd
False = eee
b; True = rrr
False = fff
c; and so 
d; and so

感谢

需要两个循环:

columns = (x, y)
for a in columns:
for b in columns: 
df[a].isin(df2[b])

最新更新