I have a list of 3 item tuples i,j,k, where i is my output variable, j is the time (thus sets the sequence of the dataset) and k is the input variable. The first "hit" needs to stay at posn 1 in the results set as they are later enumerated and the order is key.
I want to extract the [i,j] for:
- k = 0.1 (rounded)
- Every 5th k = 0.1, but not every 10th
- Only extract a value if there are exactly ten k = 0.1 in a row and disregard if there are more or less (note that k = 0.1 can occur at any point so I can't just index slice)
I can do 1. and 2. but have just got a new large dataset where 3. is now a problem.
values = []
count = 0
for i,j,k in zip(a, b, c):
if float('%.1g' % k) == 0.1:
count += 1
if (count % 5) == 0 and (count % 10 != 0):
values.append([i,j])
Example (sorry for length)
a, b, c
33, 1, 0
33, 2, 0
30, 3, 0
33, 4, 0
33, 5, 0.1
33, 6, 0.1
31, 7, 0.1
33, 8, 0.1
37, 9, 0.1
33, 10, 0.1
33, 11, 0.1
36, 12, 0.1
33, 13, 0.1
33, 14, 0.1
33, 15, 5
39, 16, 5
33, 17, 0.1
33, 18, 0.1
36, 19, 0.1
33, 20, 0.1
32, 21, 0.1
33, 22, 0.1
All I want from that list is [37,9] as that is the 5th entry of a block of ten k = 0.1.