I am trying to create a new column 'score/id.size' for my current dataframe
np.random.seed(1234)
test = pd.DataFrame({'id':np.random.randint(1,5,10),
'score':np.random.uniform(0,1,10)})
test = test.sort(['id'])
test
id score
4 1 0.875933
5 1 0.357817
6 1 0.500995
3 2 0.958139
7 2 0.683463
9 2 0.370251
2 3 0.801872
0 4 0.272593
1 4 0.276464
8 4 0.712702
I want my new dataframe to be this:
id score score/id.size
4 1 0.875933 0.875933 / 3
5 1 0.357817 0.357817 / 3
6 1 0.500995 0.500995 / 3
3 2 0.958139 0.958139 / 3
7 2 0.683463 0.683463 / 3
9 2 0.370251 0.370251 / 3
2 3 0.801872 0.801872 / 1
0 4 0.272593 0.272593 / 3
1 4 0.276464 0.276464 / 3
8 4 0.712702 0.712702 / 3
Sorry if this question is too basic, I am new to Python.
Thanks!