I need to make some kind of groupment in which a new column (result) is the sum of the values column divided by number of items found? Could anyone help me, please?
For example:
Table A
+-------+------+
| item | value|
+-------+------+
| x | 100 |
| y | 200 |
| y | 400 |
+-------+------+
Correct Result:
Table B
+-------+-----------+
| item | result |
+-------+-----------+
| x | 100/1 |
| y |(200+400)/2|
+-------+-----------+
Code:
d = {'item': ['x', 'y', 'y'], 'value': [100,200,400]}
df = pd.DataFrame(data=d)
df