pingouin.dichotomous_crosstab

pingouin.dichotomous_crosstab(data, x, y)[source]

Generates a 2x2 contingency table from a pandas.DataFrame that contains only dichotomous entries, which are converted to 0 or 1.

Parameters
datapd.DataFrame

Pandas dataframe

x, ystring

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
crosstabpd.DataFrame

The 2x2 crosstab. See 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