code: def build_index_from_labels(df, indices, remove_prefix=None, types=None, axis=1):
      
  
      df = df.copy()
  
      if remove_prefix is None:
          remove_prefix = []
  
      if types is None:
          types = {}
  
      idx = [df.index, df.columns][axis]
  
      indexes = []
  
      for l in idx.get_level_values(0):
  
          for s in remove_prefix:
              l = l.replace(s+" ", '')
  
          ixr = []
          for n, m in indices:
              m = re.search(m, l)
              if m:
                  r = m.group(1)
  
                  if n in types:
                      # Map this value to a new type
                      r = types[n](r)
              else:
                  r = None
  
              ixr.append(r)
          indexes.append( tuple(ixr) )
  
      if axis == 0:
          df.index = pd.MultiIndex.from_tuples(indexes, names=[n for n, _ in indices])
      else:
          df.columns = pd.MultiIndex.from_tuples(indexes, names=[n for n, _ in indices])
  
      return df
docs: Build a MultiIndex from a list of labels and matching regex
  
      Supply with a dictionary of Hierarchy levels and matching regex to
      extract this level from the sample label
  
      :param df:
      :param indices: Tuples of indices ('label','regex') matches
      :param strip: Strip these strings from labels before matching (e.g. headers)
      :param axis=1: Axis (1 = columns, 0 = rows)
      :return: