简体   繁体   中英

Find Sub range of values in defined ranges

I have 3 ranges of data values in series:

min_range:

27    893.151613
26    882.384516
20    817.781935
dtype: float64

max_range:

28    903.918710
27    893.151613
21    828.549032
dtype: float64

I have created a list of ranges:

range = zip(min_range, max_range)

output:

[(893.1516129032259, 903.91870967741943), (882.38451612903225, 893.1516129032259), (817.78193548387094, 828.54903225806447)]

I have got a sub range:

sub-range1: 824 sub-range2: 825

I want to find the region in which the sub range lies.

for p,q in zip(min_range, max_range):
    if (sub-range1 > p) & (sub-range2 < q):
        print p,q

output: 817.781935484 828.549032258

I want to find the respective position from that defined "range".

Expected Output:

817.781935484 828.549032258
range = 2 (Position in the range list)

How can i achieve this? Any help would be appreciated.

Use enumerate to get the index ie

for i,(p,q) in enumerate(zip(min_range, max_range)):
    if (sub_range1 > p) & (sub_range2 < q):
        print(i)

Output : 2

A simple approach using counter.

cnt = 0
for p,q in zip(min_range, max_range):
    if (sub-range1 > p) & (sub-range2 < q):
        print p,q
        print cnt
    cnt = cnt + 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM