【问题标题】:OpenRefine - Merge multiple column values into new column should (?) workOpenRefine - 将多个列值合并到新列中应该(?)工作
【发布时间】:2020-05-08 23:14:01
【问题描述】:

我的数据包含多个列——就我的目的而言——它们是相同的。在这些地方,我需要将多个选定列中的值组合成一列。例如,将列名称 1、名称 2 和名称 3 组合成一个列名称。

按照here 的指导,我正在尝试创建一个包含多列值的新列,如下图所示:

相信我的 GREL 在这里应该结合 dc.contributor.author 中的值(只需 value,因为这是我从中选择的列 编辑列 > 在此列基础上添加列)、dc.contributor.authorEN_us (cells["dc.contributor.authorEN_us"].value)、dc.contributor.author1 (cells["dc.contributor.author1"].value) 和 dc.contributor。 authoren_US (cells["dc.contributor.authoren_US"].value)。

但是,我的新列不包含来自这些第二、第三或第四列的值,即使我知道这些值存在。

我的 GREL 语法有错误吗?我应该使用不同的方法来合并列吗?

提前感谢您的帮助。

【问题讨论】:

    标签: data-cleaning openrefine grel


    【解决方案1】:

    恐怕您一直在看的教程既过时又不完整。问题是您在某些列中有值null。在 OpenRefine 中,连接(即用 + 连接两个字符串)returns null if one of the values is null

    所以:

    "Hello" + " " + "World" 给出“Hello World”。

    但是

    "Hello" + null + " " + "World" 返回null

    endless discussions关于这个问题。直到最近,我还建议您使用:

    要么:

    coalesce(value,cells['dc.contributor.author1'].value, cells['dc.contributor.authorEN_us'].value, cells['dc.contributor.authoren_US'].value)
    

    coalesce function,在 Openrefine 3 中引入,返回系列中的第一个非空值)

    或:

    value.toString() + cells['dc.contributor.authorEN_us'].value.toString() + cells['dc.contributor.authoren_US'].value.toString()
    

    (把null变成空字符串'')

    但是在未来的 OpenRefine 3.3(现在处于测试阶段)中,感谢 @mathieu-saby,OpenRefine 将提供一个菜单,让您可以轻松地合并列。你只需要update your version。 :)

    【讨论】:

    • 谢谢。有趣的是,我安装的版本是 3.2,但我没有看到“加入列”选项。暂时,我将尝试使用您的第二个示例中的toString(),看看我能得到什么结果。
    • 哎呀,你是对的:这个功能是在 3.3 中引入的,对不起:github.com/OpenRefine/OpenRefine/wiki/Changes-for-3.3我会编辑我的答案。
    【解决方案2】:

    我相信您目前仅获得第一个值,因为您仅以“值”启动 GREL。您需要使用与要连接的其他列相同的语法。所以你的表达应该是这样的:

    cells["dc.contributor.author"].value + cells["dc.contributor.authorEN_us"].value 
      + cells["dc.contributor.author1"].value + cells["dc.contributor.authoren_US"].value
    

    【讨论】:

      猜你喜欢
      • 2015-10-24
      • 1970-01-01
      • 2015-05-03
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      相关资源
      最近更新 更多