0

我在 Google 优化中有以下逗号分隔的 CSV 文件:

在此处输入图像描述

如何使用 Jython 或 GREL 填写 column1 中的值以变为:

在此处输入图像描述

我努力了:

if value is None:
 return row["record"]["cells"]["column1"]["value"][0]
else:
 return value

有什么建议么?谢谢你

4

1 回答 1

1

您的示例中棘手的部分是记录 id 1,因为您在同一记录中的 column1 中有两个不同的值。

所以要完成这个你必须

  1. ID通过合并你的和字段来创建一个新索引column1(参见 教程
  2. 使用表达式row.record.cells["Column1"].value[0]填写(见 教程

我已经通过 6 个步骤成功完成了这里是适用于您的项目的 JSON 代码:

    [
  {
    "op": "core/column-addition",
    "description": "Create column ID2 at index 2 based on column Column1 using expression grel:cells['ID'].value+value",
    "engineConfig": {
      "facets": [],
      "mode": "record-based"
    },
    "newColumnName": "ID2",
    "columnInsertIndex": 2,
    "baseColumnName": "Column1",
    "expression": "grel:cells['ID'].value+value",
    "onError": "set-to-blank"
  },
  {
    "op": "core/text-transform",
    "description": "Text transform on cells in column ID2 using expression grel:cells['ID'].value",
    "engineConfig": {
      "facets": [
        {
          "invert": false,
          "expression": "isBlank(value)",
          "selectError": false,
          "omitError": false,
          "selectBlank": false,
          "name": "ID",
          "omitBlank": false,
          "columnName": "ID",
          "type": "list",
          "selection": [
            {
              "v": {
                "v": false,
                "l": "false"
              }
            }
          ]
        },
        {
          "invert": false,
          "expression": "isBlank(value)",
          "selectError": false,
          "omitError": false,
          "selectBlank": false,
          "name": "Column1",
          "omitBlank": false,
          "columnName": "Column1",
          "type": "list",
          "selection": [
            {
              "v": {
                "v": true,
                "l": "true"
              }
            }
          ]
        }
      ],
      "mode": "row-based"
    },
    "columnName": "ID2",
    "expression": "grel:cells['ID'].value",
    "onError": "keep-original",
    "repeat": false,
    "repeatCount": 10
  },
  {
    "op": "core/text-transform",
    "description": "Text transform on cells in column ID2 using expression grel:cells['Column1'].value",
    "engineConfig": {
      "facets": [
        {
          "invert": true,
          "expression": "value",
          "selectError": false,
          "omitError": false,
          "selectBlank": true,
          "name": "Column1",
          "omitBlank": false,
          "columnName": "Column1",
          "type": "list",
          "selection": [
            {
              "v": {
                "v": " ",
                "l": " "
              }
            }
          ]
        },
        {
          "invert": false,
          "expression": "isBlank(value)",
          "selectError": false,
          "omitError": false,
          "selectBlank": false,
          "name": "ID",
          "omitBlank": false,
          "columnName": "ID",
          "type": "list",
          "selection": [
            {
              "v": {
                "v": true,
                "l": "true"
              }
            }
          ]
        }
      ],
      "mode": "row-based"
    },
    "columnName": "ID2",
    "expression": "grel:cells['Column1'].value",
    "onError": "keep-original",
    "repeat": false,
    "repeatCount": 10
  },
  {
    "op": "core/column-move",
    "description": "Move column ID2 to position 0",
    "columnName": "ID2",
    "index": 0
  },
  {
    "op": "core/text-transform",
    "description": "Text transform on cells in column Column1 using expression grel:row.record.cells[\"Column1\"].value[0]",
    "engineConfig": {
      "facets": [],
      "mode": "record-based"
    },
    "columnName": "Column1",
    "expression": "grel:row.record.cells[\"Column1\"].value[0]",
    "onError": "keep-original",
    "repeat": false,
    "repeatCount": 10
  },
  {
    "op": "core/column-removal",
    "description": "Remove column ID2",
    "columnName": "ID2"
  }
]
于 2013-01-18T04:00:14.547 回答