I have a CSV file that has rows, where data for some columns only appear in one of those rows, with other columns repeating their value:
Heading1, Heading2, Heading3, Heading4
1 , 2 , , 4
1 , , 3 , 4
How can I end up with:
Heading1, Heading2, Heading3, Heading4
1 , 2 , 3 , 4
I want to group on Heading1 and Heading4 as they are unique to the repeated rows and get the first non-blank value for all other rows, ending up with a single string[].
I’ve got as far as grouping on new { Header1, Header4 } to get a group of rows, but I’m having a hard time turning that into something where I can select the first non null value for each column, then turning it back into a single row (string[]).
Ideally I’d like a function that works with any number of columns as in the actual file there are a large number.
1 Answer