How to input multiple indices on pd.crosstab?



On this tutorial:

The author uses crosstab for showing credit history vs loan status, but then shows a graph with BOTH the credit history and GENDER in one stacked crosstab.

how do I get both those to show up? I tried making up a new df with both of those values together, but does not work.
Basically, I want to know what he did to get that bar graph with the gender, credit history and loan status. (it’s around 40-50% of the way down from the top of the page).


Hi @gcowner,

You can use the below code in python to get the bar graph of gender and credit history wise loan status:

temp4 = pd.crosstab(columns=df['Loan_Status'],index=[df["Credit_History"],df["Gender"]],margins=False) 
temp4.plot(kind='bar', stacked=True, color=['red','blue'], grid=False)