[SciPy-user] Save column & row headers to csv file with something like savetxt?

Johann Rohwer jr at sun.ac.za
Fri Dec 19 10:10:17 EST 2008


Hi Dharhas

You can use xlwt to write to an Excel spreadsheet directly, there is 
no need to go via a csv file. Then you can specify what exactly 
should go into every cell.

e.g.

import xlwt
wb=xlwt.Workbook()
ws=wb.add_sheet('results')
ws.write(0,0,'location')
ws.write(0,1,'max')

# data in array mydata
for i in range(mydata.shape[0]):
    for j in range(mydata.shape[1]):
        ws.write(i+1,j+1,data[i,j])

wb.save("myresults.xls")

etc.etc.

HTH
Johann

On Friday, 19 December 2008, Dharhas Pothina wrote:
> Hi,
>
> I have a 2D array of results that my script has calculated. I want
> to save them as a csv file so I can use them in excel or a report
> later. Is there a way to put comment lines, column & row headers in
> the text file? I had a look through the documentation but didn't
> find anything obvious.
>
> What I would like to do is save a ascii file something like below:
>
> location,max,min
> jdm1,6,2
> jdm2,4.3,1.7
> mcf1,7.7,2.2
> ...
>
> Is there already a simple way to do this?
>
> Another i/o question is that I keep getting a warning that fread is
> depreciated. I am using it to read binary fortran data, what is the
> appropriate function to use now?
>
> thanks,
>
> - dharhas



More information about the SciPy-User mailing list