Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am reading my csv which looks like:

float,float,float,integer,boolean

I read it with:

table = Take[Import["~/myfile.csv"]];
x = table[[All, 1]];
y = table[[All, 2]];
z = table[[All, 3]];
time = table[[All, 4]];
bool = table[[All, 5]];

Then I do some job with x,y,z and I need to export it back to csv. But I dont know how to get the table to export.

share|improve this question
2  
Put it in a list like so: list={x, y, z, time, bool}; and then Export["newfile.csv",list,"CSV"] – C. E. Apr 13 '14 at 20:12
    
it puts every table into one row. I need it as columns seperated by comma – SpeedEX505 Apr 13 '14 at 20:19
    
I what @Pickett suggests is basically correct, but I also that you get an output table more to your liking by using list = Transpose @ {x, y, z, time, bool};. That will put things back into columns. – m_goldberg Apr 13 '14 at 20:21
1  
BTW, {x, y, z, time, bool} = Transpose[table]; is an easy way to extract column data. – m_goldberg Apr 13 '14 at 20:24
    
It works, thank you :) If you write it as an answer I'll mark it as solved. – SpeedEX505 Apr 13 '14 at 20:25
up vote 4 down vote accepted

This is a job for Transpose.

table = Take[Import["~/myfile.csv"]];
{x, y, z, time, bool} = Transpose[table];
(* do stuff *)
output = Transpose[{x, y, z, time, bool}];
Export["newfile.csv", output, "CSV"]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.