Re: [SciPy-user] Table like array
![](https://secure.gravatar.com/avatar/49df8cd4b1b6056c727778925f86147a.jpg?s=120&d=mm&r=g)
Michael Sorich wrote:
You could subclass the ndarray to produce one of these fairly easily, I think. The missing data item could be handled by a mask stored along with the array (or even in the array itself). Or you could use a masked array as your core object (though I'm not sure how it handles the arbitrary (i.e. record-like) data-types yet). Alternatively, and probably the easiest way to get started, you could just create your own table-like class and use simple 1-d arrays or 1-d masked arrays for each of the columns --- This has always been a way to store record-like tables. It really depends what you want the data-frames to be able to do and what you want them to "look-like."
Adding a new column/field means basically creating a new array with a new data-type and copying data over into the already-defined fields. Data-types always have a fixed number of bytes per item. What those bytes represent can be quite arbitrary but it's always fixed. So, it is always "more work" to insert a new column. You could make that seamless in your table class so the user doesn't see it though. You'll want to thoroughly understand the dtype object including it's attributes and methods. Particularly the fields attribute of the dtype object.
Adding a new row or record is actually similar because once an array is created it is usually resized by creating another array and copying the old array into it in the right places.
Right. So far you can't select multiple columns. It would be possible to add this feature with a little-bit of effort if there were a strong demand for it, but it would be much easier to do it in your subclass and/or container class. How many people would like to see x['f1','f2','f5'] return a new array with a new data-type descriptor constructed from the provided fields?
Adding fieldnames to the "rows" is definitely something that a subclass would be needed for. I'm not sure how you would even propose to select using row names. Would you also use getitem semantics?
I don't know of code that already exists for this, but I don't think it would be too hard to construct your own data-frame object. I would probably start with an implementation that just used standard arrays of a particular type to represent the internal columns and then handle the indexing using your own over-riding of the __getitem__ and __setitem__ special methods. This would be the easiest to get working, I think. -Travis
![](https://secure.gravatar.com/avatar/a107cb52bd7c6ed14bb2dc43f1d9d63e.jpg?s=120&d=mm&r=g)
On 3/1/06, Travis Oliphant <oliphant.travis@ieee.org> wrote:
How many people would like to see x['f1','f2','f5'] return a new array with a new data-type descriptor constructed from the provided fields?
+1 I'm surprised that it's not already available. -- Paul
![](https://secure.gravatar.com/avatar/b24e93182e89a519546baa7bafe054ed.jpg?s=120&d=mm&r=g)
Paul Barrett wrote:
I would like some clarification as to just what is proposed. The expression looks like a subscription but the purpose is closer to that of a function or method. Is this a new method for something which can be done easily in the standard way? -1 Colin W
![](https://secure.gravatar.com/avatar/a107cb52bd7c6ed14bb2dc43f1d9d63e.jpg?s=120&d=mm&r=g)
On 3/1/06, Travis Oliphant <oliphant.travis@ieee.org> wrote:
How many people would like to see x['f1','f2','f5'] return a new array with a new data-type descriptor constructed from the provided fields?
+1 I'm surprised that it's not already available. -- Paul
![](https://secure.gravatar.com/avatar/b24e93182e89a519546baa7bafe054ed.jpg?s=120&d=mm&r=g)
Paul Barrett wrote:
I would like some clarification as to just what is proposed. The expression looks like a subscription but the purpose is closer to that of a function or method. Is this a new method for something which can be done easily in the standard way? -1 Colin W
participants (3)
-
Colin J. Williams
-
Paul Barrett
-
Travis Oliphant