I have a data frame that looks like below:
x_1 x_2 x_3 x_combined
0 1 0 [0,1,0]
1 0 1 [1,0,1]
1 1 0. [1,1,0]
0 0 1 [0,0,1]
Then I calculated the centroid of each dimension by using np.mean(df['x_combined'], axis=0) and got
array([0.5, 0.5, 0.5])
How do I now append it back to the original DF as a fifth column and have the same value for each row? It should look like this:
x_1 x_2 x_3 x_combined centroid
0 1 0 [0,1,0] [0.5, 0.5, 0.5]
1 0 1 [1,0,1] [0.5, 0.5, 0.5]
1 1 0. [1,1,0] [0.5, 0.5, 0.5]
0 0 1 [0,0,1] [0.5, 0.5, 0.5]