2
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Put it in a list like so: list={x, y, z, time, bool}; and then Export["newfile.csv",list,"CSV"] $\endgroup$ – C. E. Apr 13 '14 at 20:12
  • $\begingroup$ it puts every table into one row. I need it as columns seperated by comma $\endgroup$ – SpeedEX505 Apr 13 '14 at 20:19
  • $\begingroup$ 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. $\endgroup$ – m_goldberg Apr 13 '14 at 20:21
  • 1
    $\begingroup$ BTW, {x, y, z, time, bool} = Transpose[table]; is an easy way to extract column data. $\endgroup$ – m_goldberg Apr 13 '14 at 20:24
  • $\begingroup$ It works, thank you :) If you write it as an answer I'll mark it as solved. $\endgroup$ – SpeedEX505 Apr 13 '14 at 20:25
4
$\begingroup$

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"]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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