I have a list of numbers inside of a pandas dataframe and i am trying to use a lambda function + list comprehension to remove values from these lists.
col 1 col2
a [-1, 2, 10, 600, -10]
b [-0, -5, -6, -200, -30]
c .....
etc.
df.col2.apply(lambda x: [i for i in x if i>= 0]) #just trying to remove negative values
numbers are always ascending and can be all negative, all positive or a mix. lists are about 200 items long all integers.
I get this error:
TypeError: 'numpy.float64' object is not iterable
Edit: when i do it this way it works
[i for i in df[col2][#] if i >= 0] i guess i could run this through a for loop.. seems slow though
Edit2: looking at it with fresh eyes. turns out that the column isn't entirely made up of lists there are a few float values spread throughout (duh). Something weird was going on with the merge, once i corrected that the code above worked as expected. Thanks for the help!
lambdaa variable, convert your column into a list, then pass it through.