[SciPy-User] Select rows according to cell value

Andreas Hilboll lists at hilboll.de
Tue Nov 13 11:10:46 EST 2012


Am Di 13 Nov 2012 17:07:19 CET schrieb Juan Luis Cano Rodríguez:
> I am loading some tabular data of the form
>
>   alt    temp    press    dens
>   10.0    223.3    26500    0.414
>   10.5    220.0    24540    0.389
>   11.0    216.8    22700    0.365
>   11.5    216.7    20985    0.337
>   12.0    216.7    19399    0.312
>   12.5    216.7    17934    0.288
>   13.0    216.7    16579    0.267
>   13.5    216.7    15328    0.246
>   14.0    216.7    14170    0.228
>
> into an ordinary NumPy array using np.loadtxt. I would like though to
> select the rows according to the altitude level, that is:
>
>     >>> data = np.loadtxt('data.txt', skiprows=1)
>     >>> altitudes = [10.5, 11.5, 14.0]
>     >>> d = ...  # some simple syntax involving data and altitudes
>     >>> d
>     10.5    220.0    24540    0.389
>     11.5    216.7    20985    0.337
>     14.0    216.7    14170    0.228
>
> I have tried a cumbersome expression which traverses all the array,
> then uses a list comprehension, converts to an array... but I'm sure
> there must be a simpler way. I've also looked at argwhere. Or maybe I
> should use pandas?
>
> Thank you in advance.
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

+1 for using pandas



More information about the SciPy-User mailing list