Reputation: 879
I have a dataframe containing a column of values (X).
df = pd.DataFrame({'X' : [2,3,5,2]})
For each row, I would like to find the average of the X values from the other rows (A).
Upvotes: 0
Views: 210
Reputation: 148910
The mean of the other rows is the sum of the column minus the row value divided by the size of the column minus 1. In Pandas it writes:
df['A'] = (df['X'].sum() - df['X'])/(len(df) - 1)
Upvotes: 4