docs: def aggregate_by_index(self, function, level=0):
          """
          Aggregrate data in each record, grouping by index values.
  
          For each unique value of the index, applies a function to the group
          indexed by that value. Returns a Series indexed by those unique values.
          For the result to be a valid Series object, the aggregating function should
          return a simple numeric type. Also allows selection of levels within a
          multi-index. See select_by_index for more info on indices and multi-indices.
  
          Parameters
          ----------
          function : function
              Aggregating function to map to Series values. Should take a list or ndarray
              as input and return a simple numeric value.
  
          level : list of ints, optional, default=0
              Specifies the levels of the multi-index to use when determining unique index values.
              If only a single level is desired, can be an int.
          """
          result = self._map_by_index(function, level=level)
          return result.map(lambda v: array(v), index=result.index)