I have a numpy 2D array as follows
gona = array([['a1', 3], ['a2', 5], ['a3', 1], ['a3', 2], ['a3', 1], ['a1', 7]])
This array has 2 columns
What I want to do is create an array with 2 columns. Column 1 should have 'a1' , 'a2', 'a3' values in its' rows and column 2 should have summation of those corresponding values.
new_gona = array([['a1', 10], ['a2', 5], ['a3', 4]])
Here, corresponding values are taken as follows.
'a1' : 3 + 7 = 10
'a2' : 5
'a3' : 1 + 2 + 1 = 4
What would be an easy method to achieve this?
'|S2'. This means that the integers are stored as strings, instead of asint32or some other reasonable dtype. That may be a problem.