【问题标题】:I have below dataset and i want to change this data into target output datatset on the basis of number of repetitions我有以下数据集,我想根据重复次数将此数据更改为目标输出数据集
【发布时间】:2019-04-12 10:54:14
【问题描述】:

我有以下数据集,我想对我的行进行多次重复并为它们分配索引。

提前致谢。感谢每一个建议:)

输入:

Col1    col2    col3    repetition
101 test1   10      2
102 test2   20      1
103 test3   30      2
104 test4   40      1

输出:

col1            col2           col3       index
101     test1       10      1
101     test1       10      2
102     test2       20      1
103     test3       30      1
103     test3       30      2
104     test4       40      1

【问题讨论】:

  • 这是学校作业吗?

标签: java apache-spark apache-spark-sql


【解决方案1】:

这里有一些 java 代码描述了实现这一点的算法:

List<InputType> inputList = getInput();
List<OutputType> outputList = new ArrayList<>();

foreach(InputType input in inputList){
	for(int index = 1; index <= input.repetition){
		OutputType output = new OutputType(input.col1, input.col2, input.col3, index);
		outputList.add(output)
	}
}

System.out.println(outputList);

【讨论】:

    猜你喜欢
    • 2022-06-17
    • 2021-05-23
    • 1970-01-01
    • 2019-02-19
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多