如何从 Talend 中的一行创建多行?

问题描述

我有这样的数据:

def csvReader(filename): #Function for reading .csv file
     with open(filename) as file:

          reader = csv.reader(file,delimiter=' ')
          next(reader,None)

          data = [tuple(map(int,row)) for row in reader]
     return(data) 

csvReader('data.csv')

如何根据 Name | Address | FormName John | 123 Apple Drive | Form1 Form2 Form3 Dave| 133 Westchester Drive | Form1 Form2 Form3 列将其转换为多行?所以结果是:

FormName

因此为每个人的每个表单创建了一行。

我尝试使用 Name | Address | FormName John | 123 Apple Drive | Form1 John | 123 Apple Drive | Form2 John | 123 Apple Drive | Form3 Dave| 133 Westchester Drive | Form1 Dave| 133 Westchester Drive | Form2 Dave| 133 Westchester Drive | Form3 组件,但这对于这个简单的任务来说似乎太复杂了。

解决方法

我发现 tNormalize 正是这样做的!我像这样将 tNormalize 连接到我的 tMapimg1

tNormalize 组件中,我指定了我想要分隔的内容(空格)以及要标准化的列enter image description here

,

一种方法:

  1. 循环数据集中的每一行。

1.1.将姓名和地址放入“当前人员”字符串中。

1.2.当你到达表单“字段”时,解析它。

1.2.1.对于表单域中的每个表单

1.2.2.打印(添加到向量等)“当前人”+“当前表单” - 连接。

这是一种非常基本、直接的方法,所以首先要了解它的工作原理,然后再考虑其他方法 - 如果有的话。