I am trying to study the probability of having a zero value in my data and I have developed a code that outputs the value of a column of data when the other is zero which is what I need. But having to do that for each column vs all other 28 of my 577by29 dataframe is difficult so I decided to create a for loop that does that for me where I have this:
import numpy as np
import pandas as pd
allchan = pd.read_csv('allchan.csv',delimiter = ' ')
allchanarray = np.array(allchan)
dfallchan = pd.DataFrame(allchanarray,range(1,578),dtype=float)
y = pd.DataFrame()
x = pd.DataFrame()
for n in range(0,29):
x[n] = dfallchan[(dfallchan[0]>0) & (dfallchan[n]==0)][0]
y[n] = x[n].count()
x.to_excel('n.xlsx', index=False, sheet_name='ValForOtherZero')
y.to_excel('v.xlsx', index=False, sheet_name='CountOfZeroVlas')
The problem that is that the loop for some reason goes properly through the lines:
x[n] = dfallchan[(dfallchan[0]>0) & (dfallchan[n]==0)][0]
y[n] = x[n].count()
but it repeats the value of n=6 for the second condition:
(dfallchan[n]==0)
the output of the code should return different values of the first channel as the zeros are randomly distributed in my input file, but my output is correct for the data until the the 6th column -as my columns(0-5) should be empty- where it repeats the output for all other columns! output: output 1
you can see that the code loops correctly as the output data frame has n=29 columns but not for the condition specified above.
Please help, Thanks!