I am trying to create a histogram from grouped data in pandas.
So far, I have managed to create a standard plot line. But I can’t understand how to do the same to get a histogram (histogram). I would like to get 2 age histograms of people who have survived in the Titanic and who haven’t - to see if there is a difference in the distribution of age.
Source data:
https://www.udacity.com/api/nodes/5454512672/supplemental_media/titanic-datacsv/download
So far my code is:
import pandas as pn
titanic = pn.DataFrame.from_csv('titanic_data.csv')
SurvivedAge= titanic.groupby(['Survived','Age']).size()
SurvivedAge=SurvivedAge.reset_index()
SurvivedAge.columns=['Survived', 'Age', 'Num']
SurvivedAge.index=(SurvivedAge['Survived'])
del SurvivedAge['Survived']
SurvivedAget=SurvivedAge.reset_index().pivot('Age', 'Survived','Num')
SurvivedAget.plot()
when I try to build a histogram from this dataset, I get strange results.
SurvivedAget.hist()
I would be grateful for your help in this.