I need to calculate the mean and standard deviation of a certain column in DataFrame so that the mean and standard deviation for each row is calculated excluding the value of the row for which it's calculated.
I know I can iterate each row by index, dropping each row by index in every iteration, and then calculate the mean. I wonder if there's a more efficient way of doing it.
df=pd.DataFrame({'marks':[10,20,30,10]})
I have one solution which works only when no element is repeating but in my data, we have 10 repeating two times so my approach doesn't work.
Approach:
data['marks'].apply(lambda x: data.loc[data.marks!= x, 'marks'].mean())
data['marks'].apply(lambda x: np.std(data.loc[data.marks!= x, 'marks']))
Can someone help me with this, please?