Ask Your Question

export data and labels in cvs file

asked 2014-07-13 18:08:16 -0500

mresimulator gravatar image

updated 2014-07-14 18:35:18 -0500

Hi experts!

I have the Numpy arrays AAA=[a1,a2,...] and BBB=[b1,b2,...]. I know that I can export these arrays doing:

np.savetxt('array AAA.csv', AAA, delimiter=',') 
np.savetxt('array BBB.csv', BBB, delimiter=',')

I wanna export one csv file that include both arrays + labels, in this way:

a1  | b1
a2  | b2
.   |  . 
.   |  . 
.   |  .

How can I do that?

Waiting for your answers.

Thanks a lot.

Best regards

edit retag flag offensive close merge delete


Do you mean a csv file? In that case, perhaps taking a look at the `csv` module documentation might be helpful. The [third]( example there that might be useful for your purposes. It might help to send as input to the `writerows` method the `zip` of `AAA` and `BBB` from your example.

fidbc gravatar imagefidbc ( 2014-07-13 19:30:41 -0500 )edit

Thanks a lot fidbc!!

mresimulator gravatar imagemresimulator ( 2014-07-14 18:54:24 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-14 17:03:33 -0500

tmonteil gravatar image

You can do:

sage: C = zip(A, B)
sage: with open('file_path.csv', 'w') as f:
....:     c = csv.writer(f)
....:     c.writerows(C)
edit flag offensive delete link more


Thanks tmonteil !!

mresimulator gravatar imagemresimulator ( 2014-07-14 18:54:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-07-13 18:08:16 -0500

Seen: 155 times

Last updated: Jul 14 '14