code: def to_array_list(df, length=None, by_id=True):
      
  
      if by_id:
          assert 'id' in df.columns
  
          # if `id` is the only column, don't sort it (and don't remove it)
          if len(df.columns) == 1:
              by_id = False
  
      idx = df.index.unique()
      if length is None:
          length = max(idx) + 1
  
      l = [np.empty(0) for _ in xrange(length)]
      for i in idx:
          a = df.loc[i]
          if by_id:
              if isinstance(a, pd.Series):
                  a = a[1:]
              else:
                  a = a.copy().set_index('id').sort_index()
  
          l[i] = a.values.reshape((-1, a.shape[-1]))
      return np.asarray(l)
docs: Converts a dataframe to a list of arrays, with one array for every unique index entry.
      Index is assumed to be 0-based contiguous. If there is a missing index entry, an empty
      numpy array is returned for it.
      Elements in the arrays are sorted by their id.
      :param df:
      :param length:
      :return: