【问题标题】:For loop in pandas dataframe column对于熊猫数据框列中的循环
【发布时间】:2022-11-18 05:12:03
【问题描述】:

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

df[x].isin(df2[x]) 
df[x].isin(df2[y])
df[y].isin(df2[x])
df[y].isin(df2[x])

x 和 y 是我的两个数据框的列名。我怎样才能在循环中做到这一点?所以可以很优雅。

谢谢

【问题讨论】:

    标签: python pandas loops for-loop


    【解决方案1】:

    你需要两个循环:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 2017-06-08
      • 2015-09-19
      • 1970-01-01
      相关资源
      最近更新 更多