Outputting arrays.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Outputting arrays.

Alexandra Geddes
Hi.

1. Is there a module or other code to write arrays to databases (they want access databases)?

2. How can i write 2D arrays to textfiles with labels on the rows and columns?

thanks!
alex.


     
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Outputting arrays.

Chris Barker - NOAA Federal
Alexandra Geddes wrote:
> 1. Is there a module or other code to write arrays to databases (they want access databases)?

I don't think there is any way to write an access database file from
Python except using com on Windows.

> 2. How can i write 2D arrays to textfiles with labels on the rows and columns?

I'm not sure it there is an out of the box way, but it's easy to write
by hand, just loop through the array.

-Chris



--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Outputting arrays.

Tim Hochberg
In reply to this post by Alexandra Geddes


On Wed, May 21, 2008 at 12:32 AM, Alexandra Geddes <[hidden email]> wrote:
Hi.

1. Is there a module or other code to write arrays to databases (they want access databases)?

If you have $$, I think you can use mxODBC. Otherwise, I believe that you have to use COM as Chris suggested.


2. How can i write 2D arrays to textfiles with labels on the rows and columns?

I'm not sure it will do what you want, but you might want to look at the csv module.

 


thanks!
alex.



_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion



--
. __
. |-\
.
. [hidden email]
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Outputting arrays.

Alan G Isaac
In reply to this post by Alexandra Geddes
On Wed, 21 May 2008, Alexandra Geddes apparently wrote:
> 2. How can i write 2D arrays to textfiles with labels on the rows and columns?

http://code.google.com/p/econpy/source/browse/trunk/utilities/text.py

hth,
Alan Isaac



_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Outputting arrays.

Matt Knox-4
In reply to this post by Alexandra Geddes
> 1. Is there a module or other code to write arrays to databases (they want
access databases)?

There are three python odbc modules (mxODBC, ceODBC, pyodbc), all of which
should allow you to connect to access databases. I've played around with all
three and my personal favourite is ceODBC (which is probably the least well
known too).

Here is a quick summary of the three:

mxODBC:
 pros: fast, reliable
 cons: not free, uses mx.DateTime objects for dates instead of standard python
datetime

pyodbc:
 pros: free
 cons: last time I used it, it was quite buggy. It's slow for some things. Uses
a wierd custom "row" object instead of standard tuples in the results.

ceODBC:
 pros: free, fast, reliable
 cons: doesn't seem to be very actively developed, but the existing code is very
good

Now, as for how you use these to store arrays in a db...  I have a brief
tutorial on the timeseries wiki (http://scipy.org/scipy/scikits/wiki/TimeSeries)
for working with timeseries objects and relational databases. The same general
approach works for standard arrays. The key is to make use of the executemany
method in the database modules for inserting, and use the python zip function a
lot and the tolist method of arrays. Note that if you are inserting a one
dimensional array, you'll need to do "myarray.reshape((myarray.size,
1)).tolist()" to pass it as a parameter to executemany (so you get a list of
"rows" instead of just a single list of numbers).

If you need more detail, let me know and I can make a fuller example.

- Matt



_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion