code: def dichotomous_crosstab(data, x, y):
      """
      Generates a 2x2 contingency table from a :py:class:`pandas.DataFrame` that
      contains only dichotomous entries, which are converted to 0 or 1.
  
      Parameters
      ----------
      data : :py:class:`pandas.DataFrame`
          Pandas dataframe
      x, y : string
          Column names in ``data``.
  
          Currently, Pingouin recognizes the following values as dichotomous
          measurements:
  
          * ``0``, ``0.0``, ``False``, ``'No'``, ``'N'``, ``'Absent'``,\
          ``'False'``, ``'F'`` or ``'Negative'`` for negative cases;
  
          * ``1``, ``1.0``, ``True``, ``'Yes'``, ``'Y'``, ``'Present'``,\
          ``'True'``, ``'T'``, ``'Positive'`` or ``'P'``,  for positive cases;
  
          If strings are used, Pingouin will recognize them regardless of their
          uppercase/lowercase combinations.
  
      Returns
      -------
      crosstab : :py:class:`pandas.DataFrame`
          The 2x2 crosstab. See :py:func:`pandas.crosstab` for more details.
  
      Examples
      --------
      >>> import pandas as pd
      >>> import pingouin as pg
      >>> df = pd.DataFrame({'A': ['Yes', 'No', 'No'], 'B': [0., 1., 0.]})
      >>> pg.dichotomous_crosstab(data=df, x='A', y='B')
      B  0  1
      A
      0  1  1
      1  1  0
      """
      crosstab = pd.crosstab(
          _dichotomize_series(data, x), _dichotomize_series(data, y)
      )
      shape = crosstab.shape
      if shape != (2, 2):
          if shape == (2, 1):
              crosstab.loc[:, int(not bool(crosstab.columns[0]))] = [
                  0,
                  0,
              ]
          elif shape == (1, 2):
              crosstab.loc[int(not bool(crosstab.index[0])), :] = [0, 0]
          else:  # shape = (1, 1) or shape = (>2, >2)
              raise ValueError(
                  "Both series contain only one unique value. "
                  "Cannot build 2x2 contingency table."
              )
      crosstab = crosstab.sort_index(axis=0).sort_index(axis=1)
      return crosstab
  
file_path: pingouin/pingouin/contingency.py
imports: import warnings
  import numpy
  import pandas
  from scipy.stats.contingency import expected_freq
  from scipy.stats import power_divergence, binom, chi2
  from pingouin import power_chi2, _postprocess_dataframe
label_desc: Use image node_id 4 for calling a global function with example usage: dichotomous_crosstab(data, x, y) and returns: crosstab