docstr: index : index-like
      Can be pandas MultiIndex or Index or array-like. If array-like
      and is a MultipleIndex (more than one grouping variable),
      groups are expected to be in each row. E.g., [('red', 1),
      ('red', 2), ('green', 1), ('green', 2)]
  names : list or str, optional
      The names to use for the groups. Should be a str if only
      one grouping variable is used.
  
  Notes
  -----
  If index is already a pandas Index then there is no copy.
docstr_tok: ["index",":","index-like","Can","be","pandas","MultiIndex","or","Index","or","array-like",".","If","array-like","and","is","a","MultipleIndex","(","more","than","one","grouping","variable",")",",","groups","are","expected","to","be","in","each","row",".","E.g.",",","[","(","'red","'",",","1",")",",","(","'red","'",",","2",")",",","(","'green","'",",","1",")",",","(","'green","'",",","2",")","]","names",":","list","or","str",",","optional","The","names","to","use","for","the","groups",".","Should","be","a","str","if","only","one","grouping","variable","is","used",".","Notes","--","--","-","If","index","is","already","a","pandas","Index","then","there","is","no","copy","."]
code: def __init__(self, index, names=None):
      """
      index : index-like
          Can be pandas MultiIndex or Index or array-like. If array-like
          and is a MultipleIndex (more than one grouping variable),
          groups are expected to be in each row. E.g., [('red', 1),
          ('red', 2), ('green', 1), ('green', 2)]
      names : list or str, optional
          The names to use for the groups. Should be a str if only
          one grouping variable is used.
  
      Notes
      -----
      If index is already a pandas Index then there is no copy.
      """
      if isinstance(index, (Index, MultiIndex)):
          if names is not None:
              if hasattr(index, "set_names"):  # newer pandas
                  index.set_names(names, inplace=True)
              else:
                  index.names = names
          self.index = index
      else:  # array_like
          if _is_hierarchical(index):
              self.index = _make_hierarchical_index(index, names)
          else:
              self.index = Index(index, name=names)
          if names is None:
              names = _make_generic_names(self.index)
              if hasattr(self.index, "set_names"):
                  self.index.set_names(names, inplace=True)
              else:
                  self.index.names = names
  
      self.nobs = len(self.index)
      self.nlevels = len(self.index.names)
      self.slices = None
  
imports: from statsmodels.compat.python import lrange, lzip
  import numpy
  import pandas
  import statsmodels.tools.data
  from pandas import Index, MultiIndex
label_desc: Use image node_id 1 to create a new Grouping object  with example: obj = Grouping(index, names)