How do I create a CSV file by hand in Chains?
AnsweredI want to create a CSV file by hand in Chains, with various different values stitched together manually to be imported into a WDesk sheet. I used Create File to specify the first line of CSV based text:
Amortization of lease payments,,,,,
and left the output file name blank. Then another one for the second line:
Payment Number,Date,Payment,Interest,Principal,Balance
and the third the output of an Array to CSV which has this content:
======== START PREVIEW ========
1,2020-04-01,1000,0,1000,56516.71
2,2020-05-01,1000,141.29,858.71,55658
3,2020-06-01,1000,139.14,860.86,54797.14
Then I used Stack Files from Tabular Transformation and specified the three output files under Files to Stack. However the result of this is wrong:
Processing file: output-1615932927707
Processing file: output-1615932933285
Processing file: 19112823_converted_1615932939038.csv
Amortization of lease payments,,,,,
1,2020-04-01,1000,0,1000,56516.71
What am I doing wrong? I want one CSV file like this:
Amortization of lease payments,,,,,
Payment Number,Date,Payment,Interest,Principal,Balance
1,2020-04-01,1000,0,1000,56516.71
2,2020-05-01,1000,141.29,858.71,55658
3,2020-06-01,1000,139.14,860.86,54797.14
-
As documented in the Stack Files command "The header row from the first file will be used in the new file." This means that the headers from the other files will be omitted. If you don't include a header, Chains will treat the first row as a header. If you want to keep the first row, it is important to include a header, even if it is just a blank row of commas.
Take for example the following three Create file nodes run through Stack Files:
Create file 1 - Text:
Amortization of lease payments,,,,,Create file 2 - Text:
Payment Number,Date,Payment,Interest,Principal,BalanceCreate file 3 - Text:
1,2020-04-01,1000,0,1000,56516.71
2,2020-05-01,1000,141.29,858.71,55658
3,2020-06-01,1000,139.14,860.86,54797.14Result of Stack Files:
Amortization of lease payments,,,,,
2,2020-05-01,1000,141.29,858.71,55658
3,2020-06-01,1000,139.14,860.86,54797.14File 1 only had one row, but from the documentation we know that it is used as the header in the new stacked file result.
File 2 also had only one row, but it is treated as a header and therefore omitted.
File 3 had three rows. After the first row is omitted (header), the second and third row are stacked in the result.Try adding a header (even a blank row such as ",,,,,") to files 2 and 3 to fix the output. Or you could put all the data in the Text field of a single Create file node to avoid having to stack the three files together to create one file.
1Hi Waldo, make sure the files you create have the same headers and the stack command should work better. Alternatively, if you have all of the data for your csv file you're creating, you could create it in one Create file node rather than splitting it into several and stacking them together.
0As you can see above my headers align (6 columns each) yet the stack fails. All CSV files do NOT have headers - I want to emit a single line and build a file. Only the last file has a header.
I tried using Create File to build all the fields in one go but it was not clear how to enter multiple rows in one line. \n does not seem to work.
Indeed I get this:
0
Comments
4 comments