【问题标题】:extract column values based on comparing one column against multiple other columns基于将一列与其他多列进行比较来提取列值
【发布时间】:2021-11-20 21:11:01
【问题描述】:

我想将 Table1 中多个列的值与 Table2 的 columnA 的值进行比较,如果匹配,则在 Table1 中创建一个新列,其中将包含 Table2 的 ColumnB 中的匹配值。

我的输入是两个表:

表1

Col1 Col2 Col3 Col4 Col5 Col6
- P2 - - - -
- - P3 - - -
- - - P4 -
P1 - - - - -

表2

ColA ColB
P1 MSH3
P2 MSH5
P3 L6
P4 V5

输出是一张表 [参见 Col 输出]:

Col1 Col2 Col3 Col4 Col5 Col6 OUTPUT
- P2 - - - - MSH5
- - P3 - - - L6
- - - P4 - - V5
P1 - - - - - MSH3

感谢您的建议。谢谢。

【问题讨论】:

    标签: match vlookup


    【解决方案1】:

    我找到了答案。如果有人遇到类似问题:

        Result = pd.DataFrame([])
        for i in DF1:
             Result = Result.append ( pd.merge(DF1, DF2, how = 'inner', left_on=i, right_on='ColA') )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多