I have a dataframe that contains the numpy object
column.The data is as follows:
data
0 [1, 2, 2, 3, 4, 2]
1 [2, 4, 2, 5, 2, 3, 2]
2 [2, 2, 2, 8, 2, 3, 2, 9, 1]
...
I would like to get the index of every numpy in the column to satisfy the condition: (>(mean+std))or(<(mean-std))
,the output I expect is as follows:
data index
0 [1, 2, 2, 3, 4, 2] [0,4]
1 [2, 4, 2, 5, 2, 3, 2] [1,3]
2 [2, 2, 2, 8, 2, 3, 2, 9, 1] [3,7]
...
My code is like this:
df['index'] = df['data'].map(lambda x: np.where(((x > x.mean() + x.std()) or (x < x.mean() - x.std())))[0])
But it has a mistake
:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
When I'm using only half of the condition(such as (>(mean+std))
), there's no problem, so I guess my expression is wrong, but I don't know how to change it.
Can someone help me? Thanks in advance