Issue
I checked w_table.iloc[i,4]
and didn't find NoneType
objects in it. What's the matter could it be?
check = ['word']
for i in range(len(w_table)):
if w_table.iloc[i, 4] != 'Null':
if w_table.iloc[i, 4] in check:
w_table = w_table.drop(w_table.index[i])
else:
check = check.append(w_table.iloc[i, 4])
w_table.index = np.arange(len(w_table))
After executing above code I am getting following TypeError
TypeError Traceback (most recent call
last) <ipython-input-74-40b9156195fa> in <module>()
2 for i in range(len(w_table)):
3 if w_table.iloc[i, 4] != 'Null':
4 if w_table.iloc[i, 4] in check:
5 w_table = w_table.drop(w_table.index[i])
6 else:
TypeError: argument of type 'NoneType' is not iterable
Solution
The problem is with this line:
check = check.append(w_table.iloc[i, 4])
list.append
is an in-place operation and returns None
. Instead, just use:
check.append(w_table.iloc[i, 4])
For better performance, use set
and set.add
:
check = {'word'}
...
check.add(w_table.iloc[i, 4])
Even better, you can use vectorised functionality to avoid loops altogether. For this, you should provide a complete example, probably in a separate question.
Answered By - jpp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.