I'm currently working on a script for automating the creation of a pivot table from raw data file and I'm quite happy with my current work.
But I would like to add another step after creating the pivot table. I need to import the data into Excel and currently I would need to group values manually in Excel, so it would be great to have this grouping action within my script.
My current pivot table looks kinda like this (the original is too big for posting it here):
10 20 30 40 50
0.2 1 0 0 1 2
1.4 0 2 1 0 0
2.0 2 0 1 0 1
2.3 0 0 2 2 0
3.6 3 0 1 1 0
4.1 1 0 2 1 0
The result should look like this:
10 20 30 40 50
0-2 3 2 2 1 3
2-4 3 0 3 3 0
> 4 1 0 2 1 0
So, the values in column 1 need to be grouped and their values in the table need to be added to each other.
My original table has field separators (;) and the groups I need are 0-2, 2-4, 4-6, 6-8, 8-10 and > 10.
So, like 0.2, 1.3, 1.9, 2.0 need to be grouped to "0-2".
2.2, 3.1, 3.6 to "2-4" and so on.
The values 2.0, 4.0, 6.0, 8.0 should be in the previous group, like 2.0 in "0-2", while the first value of "2-4" needs to be 2.1.
Originally my example had a comma as decimal separator, I can change the decimal separator to dot if needed; it's just for Excel which needs a comma when importing the table.
Any ideas how to manage this? Maybe using awk
as I did in my script to create this pivot?
Here’s the complete data:
Row Labels;10;20;30;40;50;60;70;80;90;100;110;120;130;140;150;160;170;180;190;200;210;220;230;240;250;260;270;280;290;300;310;320;330;340;350;360
0.2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1
0.3;;;;;;;;;;;1;;;;;;;1;;;;;;;;;;1;;;;;;;;
0.4;;;;;1;;1;;;;;;;;1;;;;;;;;;;;;1;;;;1;;;;;
0.5;;;;;;;1;;;;1;;;;1;1;;1;;;;;;;;1;;;;;;;;2;;
0.6;1;1;1;;1;;;;1;1;;;;;;;;;;;;;;2;1;;;;1;;1;1;;2;;
0.7;1;;;;4;;;;1;;;;;;;;;;;;;;;1;;;;1;2;;;1;1;1;1;
0.8;;1;1;2;;;2;;1;;;2;;;;;;1;;;;;;1;;1;;1;;;;1;;1;1;1
0.9;1;;;;1;3;2;;1;;1;;1;;;;;;;;;;;;;;;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