【问题标题】:Adding one table to another with one common (but shuffled) column [closed]将一个表添加到另一个具有一个常见(但已改组)列的表 [关闭]
【发布时间】:2021-08-24 09:02:57
【问题描述】:

我有 2 个带有公共列(名为 project_name)的表。 table2 中 project_name 的顺序与 table1 中的顺序不同(参考查看截图)。 我怎样才能合并两个表(在 excel 或 python 中作为数据框)?

【问题讨论】:

  • 您可以轻松地在Power Query 中使用Table.Join,可在Windows Excel 2010+ 和Office 365 中使用

标签: python excel pandas dataframe


【解决方案1】:

使用 Excel,我会使用 INDEX/MATCH,如下所示:

=INDEX(B$12:B$14,MATCH($A3,$A$12:$A$14,0))

有关 INDEX/MATCH 的完整说明,请参阅https://exceljet.net/index-and-match

#N/A 表示项目名称未出现在表 2 中,可以通过将公式包装在 IFNA 中来替换为任何所需的值:

=IFNA(INDEX(B$12:B$14,MATCH($A3,$A$12:$A$14,0)),<Value if not found>)

MATCH 返回表 2 中当前项目名称的索引。INDEX 然后使用它返回所需的数据。

完成后,您可以根据需要复制并粘贴为值以删除公式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 2020-01-23
    • 1970-01-01
    • 2021-12-10
    • 2015-07-22
    相关资源
    最近更新 更多