Dheeraj
Dheeraj

Reputation: 1202

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.

Upvotes: 2

Views: 210

Answers (2)

nayan patra
nayan patra

Reputation: 34

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

Upvotes: 0

Bharath M Shetty
Bharath M Shetty

Reputation: 30605

Use enumerate to get the index i.e

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

Output : 2

Upvotes: 4

Related Questions