[SciPy-User] Masking multiple fields in a structuredtimeseriesobject.
Tue Jan 12 14:33:47 CST 2010
Thank you, I finally got it. I guess I had difficulty in conceptually treating the series and dates separately. I kept trying to apply the masks using 'series[start:end]' and ended up with my indices mismatching.
on a related note is there any way to do the following without using a loop?
_series['name'][1:3] == 'BB'
right now this gives me 1st and 2nd entries in _series['name'] rather than the 1st and 2nd characters for all entries in _series['name']
>>> Pierre GM <email@example.com> 01/12/10 2:11 PM >>>
On Jan 12, 2010, at 1:39 PM, Dharhas Pothina wrote:
> Sorry I'm still having trouble figuring out how to do multiple masking on a limited date range rather than the entire series. For a simpler example, look at the below ts construct:
>>>> series=ts.time_series([("ABBC",1.1,10.),("ABD",2.2,20.),("ABBE",3.3,30),("ABBF",4.4,40),("ABG",5.5,50),("ABH",6.6,60)],dtype=ndtype, start_date=ts.now('D'))
>>>> sdate = series.dates
>>>> edate = series.dates
> now I want to mask the v1 value between sdate and edate that contain 'BB' in the name and v1<4 and v2>10. ie the 3rd element ("ABBE",3.3,30) would become ("ABBE",--,30)
Well, if I do your job for you, where's the fun ;) ? Seriously, why don't you build several masks and combine them as you want ?
* Make a mask M1 for the 'BB' in name (use an approach similar to which I posted last time)
* Make a mask M2 that tests the values:
* Make a mask M3 that test for the dates:
* Combine the masks to make one that satisfies all the conditions:
>>> Mall=np.array(M1&M2&M3, dtype=bool)
(we need to make sure that Mall is a boolean ndarray, and not an array of 0 and 1 else we mess up fancy indexing)
* Mask 'v1' according to the new mask:
* you use 3 characters for name, but try to put strings with 4 characters. Expect problems.
* When you build the masks, use series.series as much as you can (that'll save you some time)
SciPy-User mailing list
More information about the SciPy-User