0

I'm trying to have my function go through the spread sheet inspect every other 3 columns and find the location (row number) of some values but it works partially. The code runs and returns some values but I get this error message between and it stops.

I'm using start=mm[0] to grab the first value from the array and end=mm[-1] to grab the last value.

def get_voltageStatus(r,t):
    for i in range (1,len(data[0]),3):
        m=np.where((data[1:,i]>=r) & (data[1:,i]<=t))
        mm_raws = []
        mm=m[0]
        start=mm[0]
        end=mm[-1]
        print(data[0,i])
        duration(start,end)

Error is:

start=mm[0] IndexError: index 0 is out of bounds for axis 0 with size 0

Afrida Anzum
  • 563
  • 4
  • 19
user2241397
  • 69
  • 2
  • 11
  • No value in `data` is between `r` and `t`, so `m[0]` is empty. – Daniel Jun 27 '19 at 16:59
  • r and t are being fed somewhere else when we call the function – user2241397 Jun 27 '19 at 17:15
  • if size is 0, then there is no element, and therefore 0 is an invalid index. In other words, the error message already covered this. Note that you are looking at m[0][0] and this uses globals so hard to test/reproduce. – Kenny Ostrom Jun 27 '19 at 18:11

1 Answers1

0

this fixed the problem

def get_voltageStatus(r,t):
    all=[]
    for i in range (1,len(data[0]),3):
        m=np.where((data[1:,i]>=r) & (data[1:,i]<=t))
        print(i)
        mm_raws = []
        mm=m[0]
        if mm.any():
            start=mm[0]
            end=mm[-1]
            print(data[0,i])
            temp=duration(start,end)
            all.append([data[0,i],temp])
user2241397
  • 69
  • 2
  • 11