Вы можете использовать np.unique
и np.bincount
:
>>> inp
array([['Purple Puffin', '1', '1'],
['Wisteria Wombat', '3', '4'],
['Pumpkin Pomeranian', '1', '3'],
['Wisteria Wombat', '2', '3'],
['Burgundy Bichon Frise', '2', '1'],
['Purple Puffin', '1', '4'],
['Wisteria Wombat', '2', '2'],
['Pumpkin Pomeranian', '1', '2']], dtype='<U21')
>>> unq, inv = np.unique(inp[:, 1::-1], axis=0, return_inverse=True)
>>> cnt = np.bincount(inv, inp[:, 2].astype(int)).astype(int)
>>> res = np.c_[unq[:, ::-1], cnt]
>>> res
array([['Pumpkin Pomeranian', '1', '5'],
['Purple Puffin', '1', '5'],
['Burgundy Bichon Frise', '2', '1'],
['Wisteria Wombat', '2', '5'],
['Wisteria Wombat', '3', '4']], dtype='<U21')