My dataframe has 4 columns (one dependent variable and 3 independent).
Here's a sample:
My desired output is a contingency table, as follows:
I can only seem to get a contingency table using one independent variable- using the following code (my df is called 'table')
pd.crosstab(index=table['Dvar'],columns=table['Var1'])
I can't seem to be able to add any other variables to this...Is the only way to achieve this to do make a separate contingency table for each var (1 to 3) and then merge/ join them?