I am trying to count 'nan' in my data file.
For this purpose, I have used two codes one is:
with open(filin,'r') as f:
arrays = [map(float, line.split(',')) for line in f]
newa = [x[6] for x in arrays]
The other is:
for columns in ( raw.strip().split(',') for raw in f ):
a.append((columns[6])
newa = np.array(a)
When I used the first way, I got error message of:
Traceback (most recent call last):
File "Count_nan.py", line 13, in <module>
arrays = [map(float, line.split(',')) for line in f]
ValueError: could not convert string to float:
With second code, I can get arrays, but I could not count nan with the code of
l = np.count_nonzero(np.isnan(newa)) or
v = [len(list(group)) for key, group in groupby(newa, key=np.isnan) if key]
v is code for counting group of consecutive 'nan's.
The reason which I can't use two code above is that my newa is consist of ['1', '2.4','nan'...], not [1, 2.4, nan, ...]
Any idea or help would be really appreciated.
Beat regards,
Isaac