This widget could not be displayed.
This widget could not be displayed.

LabVIEW

This widget could not be displayed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Consolidate rows in 2D array

I need to consolidate rows in a .csv file so that multiple rows from the same user are consolidated into a single row.

Input data:

Key,Person,Amount
P-1,Bill,3.00
B-3,Joe,7.50
G-2,Jane,4.55
P-1,Bill,7.00
P-1,Bill,10.00
G-2,Jane,5.45

I need the output to add the 3rd column together and make it into a single row

Expected result:

Key,Person,Amount
P-1,Bill,20.00
B-3,Joe,7.50
G-2,Jane,10.00

 

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 1 of 13
(4,408 Views)

If you have LabVIEW 2019, a map (brand new datatype!) with key=user or key, value=array of DBL.

 

(Since you did not mention your version yet, we need to wait. Maybe something based on Variant attributes could be done for earlier LabVIEW versions. How big is the typical dataset? Is the key and person always matched?)

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 2 of 13
(4,393 Views)

My bad, I'm using LV2016

Key is indeed always tied to Name

Typical number of entries to sort is less than 100 rows

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 3 of 13
(4,378 Views)

Make an empty array of names and one for the other items.

Make a for loop, with a shift register for each array.

In the for loop, search each entry against the name array.

If it's there (use an in place element structure to) get the current value, add the new value and replace the element.

If it's not there, add the name to the array, and the values to the other arrays.

 

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 4 of 13
(4,346 Views)

I just installed LV2019

Now, you mentioned this MAP data type?

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 5 of 13
(4,333 Views)

@Murph wrote:

I just installed LV2019

Now, you mentioned this MAP data type?


Yes!

 

summarizer.png

 

(If you want the keys in original order, some changes would need to be made.)

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 6 of 13
(4,327 Views)

Awesome!

I took a more painful but successful route.

 

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 7 of 13
(4,311 Views)

Well, now you know why maps are so great 😄

(even though I see quite a bit of room for improvements in your code ;))

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 8 of 13
(4,307 Views)

I am of the many who are not programmers, just guys trying to get something done 🙂

Improvements to my code are most welcome!

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 9 of 13
(4,303 Views)

The MAP version is definitely preferred for large dataset, because the lookup is much more efficient. Just for kicks, here's a "noMap" version. This one keeps the element in order of first occurrence. There are many ways to do this, of course. 😉

 

summarizerNoMap.png

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
0 Kudos
Message 10 of 13
(4,294 Views)