code: def _normalize_dataframe(dataframe, index):
      """Take a pandas DataFrame and count the element present in the
      given columns, return a hierarchical index on those columns
      """
      # groupby the given keys, extract the same columns and count the element
      # then collapse them with a mean
      data = dataframe[index].dropna()
      grouped = data.groupby(index, sort=False, observed=False)
      counted = grouped[index].count()
      averaged = counted.mean(axis=1)
      # Fill empty missing with 0, see GH5639
      averaged = averaged.fillna(0.0)
      return averaged
  
imports: from statsmodels.compat.python import lrange, lzip
  from itertools import product
  import numpy
  from numpy import array, cumsum, iterable, r_
  from pandas import DataFrame
  from statsmodels.graphics import utils
label_desc: Use image node_id 11 for calling a global function with example usage: _normalize_dataframe(dataframe, index) and returns: averaged