docs: def fold_columns_to_rows(df, levels_from=2):
      """
      Take a levels from the columns and fold down into the row index.
      This destroys the existing index; existing rows will appear as
      columns under the new column index
  
      :param df:
      :param levels_from: The level (inclusive) from which column index will be folded
      :return:
      """
      
      df = df.copy()
      df.reset_index(inplace=True, drop=True) # Wipe out the current index
      df = df.T
      
      # Build all index combinations
  
      a = [list( set( df.index.get_level_values(i) ) ) for i in range(0, levels_from)]
      combinations = list(itertools.product(*a))
      
      names = df.index.names[:levels_from]
      
      concats = []
      for c in combinations:
          
          try:
              dfcc = df.loc[c]
  
          except KeyError:
              continue
  
          else:
              # Silly pandas
              if len(dfcc.shape) == 1:
                  continue
          
              dfcc.columns = pd.MultiIndex.from_tuples([c]*dfcc.shape[1], names=names)
              concats.append(dfcc)
  
      # Concatenate
      dfc = pd.concat(concats, axis=1)
      dfc.sort_index(axis=1, inplace=True)
  
      # Fix name if collapsed
      if dfc.index.name is None:
          dfc.index.name = df.index.names[-1]
  
      return dfc