I was learning histograms then I encountered a code for stacked histograms as follows:
temp3 = pd.crosstab([df.Pclass, df.Sex], df.Survived.astype(bool)) temp3.plot(kind='bar', stacked=True, color=['red','blue'], grid=False)
where df is a pandas dataframe and ‘Pclass’ ,‘Survived’ and ‘Sex’ are two categorical columns in the dataframe.
Survived - could be 0 or 1
PClass - Passenger travelling class- could be 1, 2 or 3
Sex - Male, Female
I could not understand the use of pd.crosstab(). Is there any other way to create stacked histograms?