def _determine_levels(index):
 if (isinstance(index, (tuple, list)) and (len(index) > 1)):
  return list(range(len(index)))
 else:
  return 0

def _determine_levels ( index ) : if ( isinstance ( index , ( tuple , list ) ) and ( len ( index ) > 1 ) ) : return list ( range ( len ( index ) ) ) else : return 0
determine the correct levels argument to groupby .