Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Skipper Seabold <jsseabold <at> gmail.com>
Subject: Re: save data to csv with column names
Newsgroups: gmane.comp.python.numeric.general
Date: Monday 16th August 2010 13:54:37 UTC (over 6 years ago)
2010/8/16 Guillaume Chérel <[email protected]>:
> Hello,
>
> I'd like to know if there is an easy way to save a list of 1D arrays to a
> csv file, with the first line of the file being the column names.
>
> I found the following, but I can't get to save the column names:
>
> data = rec.array([X1,X2,X3,X4], names=[n1,n2,n3,n4])
> savetxt("filename", data, delimiter=",", fmt=["%i","%d", "%f","%f"])
>

There is a patch to add this capability to savetxt.  It was proposed
to be included in Numpy 1.5, but I don't see that the patch was
applied yet.  You can use it for your stuff in the meantime.  I've
been using a version that I wrote since I need to do this quite often.

http://projects.scipy.org/numpy/ticket/1079

I don't remember without looking if this patch also accepts recarrays
and scrapes the names automatically.  It should.

Skipper
 
CD: 4ms