Jump to content
Hack4Life

Sum to values from a .csv and save it to a new .csv file

Recommended Posts

Hello,

I need to select a .csv file which has two integers seperated through a comma per line. I have to sume these to values and write it to a new .csv file with the two integers and as third position the result. I have a path selector and a read from spreadsheet and a write to spreadsheet element. But I do not know how to read the two values line per line and add those to values with the result in a new .csv file

 

For example:

input:

A,B
1,3
2,6
3,3

output:

A,B,C
1,3,4
2,6,8
3,3,6

I hope that somebody can help me.

 

Thanks for your help!
Greets from Austria,

Fabian

Share this post


Link to post
Share on other sites

This isn't too difficult.  Once you have the read data as an array, go into an auto indexing for loop and process each row one at a time.  Then concatenate the sum to the end, and rebuild your 2D array before writing it again.  Attach the code you've tried.

Share this post


Link to post
Share on other sites

Read Spreadsheet File and Write Spreadsheet File will get you half way there.  Hooovahh told you what to do in the middle.  Post back with some of your code if you run into issues.

Share this post


Link to post
Share on other sites
I am now here. I do not know how to split the values from the array to the sum operator..

2015 03 06

Share this post


Link to post
Share on other sites

As hooovahh said, you need to use a for loop to index into the array. Inside the for loop you will have a 1D array which you need to index the first and second elements and add them. Concatenate that with the input 1 D array.

 

Auto-indexing is your friend here.

Share this post


Link to post
Share on other sites

So I got it done now. 

My problem is that the Headers of the input file (A,B) were converted to an (0,0) in the output file because I have set the read spreadsheet element to Integer. Is there a way to exclude the file header and write (A,B,C) to my output file?

 

2015 03 06   Read Write Spreadsheed   Headers

 

Share this post


Link to post
Share on other sites

You'll likely want to read it as a string and take care of converting between strings and numbers and back.  Look for number/string conversion in the string palette. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.