I would like to add values to an array if they occur after a 100. This works fine if the column which contains a 100 isn't the last column (as the next columns value in that row will be appended to an array). But an IndexError occurs if the 100 value occurs in the last column as there's no lastcol + 1 value.
col1 col2 col3
nan 100 60
100 95 98
nan nan 100
Now:
values = [60,95,IndexError];
Ideal:
values = [60,95,100];
My code:
x1 = np.where(#table == 100.0)[0]; x2 = np.where(#table == 100.0)[1]
# np.where returns a tuple containing the (x,y) locations of
the 100 values in the table. e.g. [(0,1,2),(1,0,2)] for the
table in the above example.
for i,j in zip(x1,x2):
values.append(out[i][j+1]);
# Above attempts to add values
EDIT
col1 col2 col3 col4
nan 100 60 50
100 95 98 70
nan nan 100 80
nan nan nan 100
nan nan 100 100
Desired: Get values after 100 occurs in row and append it to the 'values' array. Also, note that nan
will occur in each row before a 100 values occurs.
values = [60,95,80,100,100];
The values above occur in each row after 100 (order is important).