On 3/22/12 12:48 PM, sreeaurovindh viswanathan wrote:
> But.. Can i get sort one column by descending and the other ascending.
> say
> if i have two columns and first i would like to sort the one in
> ascending and then sort the second column based on the search from the
> first.
>
>
> I mean I i have
>
> 1 5
> 2 6
> 1 8
> 2 9
>
> Could i get an output as
>
> 1 5
> 1 8
> 2 6
> 2 9
No, this is not supported by PyTables.
But hey, you can always make use of the sorted iterator, and the
additonal sorting by yourselves. In your example, let's suppose that
column 0 is named 'f0' and column 1 is named 'f1'. Then, the next loop:
prevval = None
gf1 = []
for r in t.itersorted('f0'):
if r['f0'] != prevval:
if gf1:
gf1.sort()
print prevval, gf1[::-1] # reverse sorted
prevval = r['f0']
gf1 = []
gf1.append(r['f1'])
if gf1:
gf1.sort()
print prevval, gf1[::-1] # reverse sorted
will print the next values:
f0-val0 [decreasing list of f1 values]
f0-val1 [decreasing list of f1 values]
...
f0-valN [decreasing list of f1 values]
Hope this helps,
-- Francesc Alted
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users