Reputation: 8291
I have a big dataframe and when I process it I receive this error
ValueError: could not convert string to float: \N
To get rid of this error I need to replace the \N values with 0. I tried this code:
set1[set1 == '\N'] = 0
#This also did not work --> set1[set1.ix[:,:] == '\N'] = 0
But, then I receive this error:
TypeError: Could not compare ['\N'] with block values
Any ideas?
Upvotes: 0
Views: 63
Reputation: 3198
This is a good use for comprehensions.
set1 = [item if item != '\N' else 0 for item in set1]
(as with the other answer, this turns 'set1' into a Python list
object; if it's something else and you want it to stay that way, this won't do the trick).
Upvotes: 1
Reputation: 757
set1 = map(lambda val: val if type(val) is str else 0, set1)
Assuming set1
is a list.
Upvotes: 1