I want to count the total occurrence of the number 5 in my dataframe df with 4 lists inside it (there are 3 numbers 5 in my df). But in my code bellow the if statement stops when it encounters the first False return and does not count the third 5 in the last list in df. How I can resolve this?
df = [[1,3,5,7,9],[1,2,3,4,5],[2,4,6,8,10],[2,5,6,8,10]]
n,m,counter=0,5,0
for i in range(4):
if df[n].count(m):
print('ok')
counter=counter+1
n=n+1
else:
print('NO')
print(counter)
for i in range(4)use something like this:for l in df: for item in l: if item==5: print('ok') counter += 1 else: print('NO') print counterdfis not a dataframe.