Aug-07-2019, 03:25 PM
(Aug-07-2019, 01:35 PM)python_newbie09 Wrote:(Aug-07-2019, 01:26 PM)paul18fr Wrote: habit coming from Mathlab (BTW it has no consequence)
I didn't understand that you want to get the number of occurences of "...85" (i.e the dots AND 85)
yes, because the list is very long so I also cannot use the method of just counting the difference as suggested above for 1000 plus rows of time series data. To make it simpler, the list below as an example:
n = [0,1,1,1,1,2,2,2,85,85,85,80,80,80,0,1,1,1,2,2,2,85,85,85,80,80,80]
I tried to use the code below with the logic of first checking if the value is 85 and if the previous value is not 85 and the next value is the same as 85 then count 1. But I am getting an error; AttributeError: 'int' object has no attribute 'iloc'
this code does not include the counting part yet.
for i, x in enumerate(n): if x==85 and x.loc[i-1]!= 85 and x.iloc[i+1]==85: print(i)
I could probably live with the solution below for now but I need to make sure that it checks until the end of the list.
a = 0 for i, x in enumerate(n): #print(n[i]) #print(n[i-1]) #print(n[i+1]) if x ==85: #print(n[i]) if n[i-1]!=85: #print(n[i-1]) if n[i+1]==85: #print(n[i+1]) a+=1 print(a)