Ask Your Question
0

export data in MS Excel file

asked 2013-07-09 12:20:37 +0200

mresimulator gravatar image

updated 2015-01-13 22:41:44 +0200

FrédéricC gravatar image

Hi experts!

Im running a code that generate three differents Numpy arrays (L1, L2 and L3) for every for-cycle (there is N cycles), so I get 3N arrays.

I wanna save these NP arrays in a MS excel file (.xls or other).

My questions are:

1) How can i generate this excel file? 2) How can I read the Excel file generated in a script?

Waiting for your answers.

Thanks a lot!

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2013-07-09 15:52:51 +0200

Eviatar Bach gravatar image

I'd recommend using CSV files, since they're the simplest and can be opened with Excel.

To save the array (see the documentation for more options, such as the precision of values to be stored):

numpy.savetxt('out.csv', L1, delimiter=',')

(For saving multiple arrays in the same file, it depends on how you want to do it. You can do numpy.vstack for stacking them of top of one another, for example.)

To read back the array:

numpy.loadtxt('out.csv', delimiter=',')
edit flag offensive delete link more
0

answered 2013-07-31 23:00:46 +0200

mresimulator gravatar image

updated 2013-07-31 23:04:03 +0200

Hi.

Thanks for the help!

Three more questions:

1) If i have a array H=[[1,2,3,4,5],[9,8,7,6,5]],when i save it like csv format, it is sabed like two rows. How can i do for save it like two columns?

2) If i have two arrays: L1=[1,2,3,4,5] and L2=[9,8,7,6,5]. How can i do for save that two arrays like two columns in one only .csv file?

3) How can i insert a title inside the .cvs file (like a comment) and a column name in each column?

Thanks again.

Waiting for yor answers.

edit flag offensive delete link more
0

answered 2013-08-01 10:06:46 +0200

calc314 gravatar image

For #1, do a transpose on the array using numpy.tranpose.

For #2, I recommend building a new array with L1 and L2 as columns and then saving it.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-07-09 12:20:37 +0200

Seen: 1,996 times

Last updated: Aug 01 '13