[英]I have below dataset and i want to change this data into target output datatset on the basis of number of repetitions
I have below dataset and i want to make repititions of my rows that number of times and assign index to them.我有以下数据集,我想对我的行进行重复次数并为它们分配索引。
Thanks in advance.提前致谢。 Every suggestion is appreciated :)
每个建议表示赞赏:)
INPUT:输入:
Col1 col2 col3 repetition
101 test1 10 2
102 test2 20 1
103 test3 30 2
104 test4 40 1
OUTPUT:输出:
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
Here is some java code that describes the algorithm to accomplish this:下面是一些 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.