code: def expected_counts(dataframe, rownames, colnames):
      
      cont_table = contingency_table(dataframe, rownames=rownames, colnames=colnames, margins=True)
      row_counts = cont_table['All']
      column_counts = cont_table.loc['All']
      total_observations = cont_table['All']['All']
  
      # There didn't seem to be a good way to vectorize this (Fixme?)
      for column in cont_table.columns:
          for row in cont_table.index:
              cont_table[column][row] = column_counts[column]*row_counts[row]/total_observations
      return cont_table
docs: Expected counts of the multivariate frequency distribution of the variables given the
         null hypothesis of complete independence between variables.
         Args:
             rownames: the column name or list of columns names that make the keys of the rows
             colnames: the column name or list of columns names that make the keys of the columns