Page 1 of 1

please fix this code. There are some errorsin ploting these graphs that I don't know. import pandas as pd import matplot

Posted: Mon May 02, 2022 12:02 pm
by answerhappygod
please fix this code. There are some errorsin ploting these graphs that I don't know.
import pandas as pd
import matplotlib.pyplot as plt
#reading csv file
titanic=pd.read_csv('Titanic_dataset.csv')
#print(first_south)
#filtering data where class is 1 and Port of Embarkation is S
filt=(titanic['Class']==1) & (titanic['Port of Embarkation']=='S')
first_south=titanic[filt][['Survival','Class','Port of Embarkation','Gender','Age group']]
print('List of passenger who is in the first class cabin and boarded from Southampton ')
print('-----------------------------------------')
print(first_south.head())#printing first 5 rows
filt=(titanic['Class']==2) | (titanic['Class']==3)
second_third=titanic[filt][['Survival','Class','Port of Embarkation','Gender','Age group']]
print('List of passenger who is in the second class or third class cabin boarded from Southampton ')
print('-----------------------------------------')
print(second_third.head())#printing first 5 rows
fs=first_south.groupby('Gender').size()#group on Gender and counting number of passengers in each group
print(fs)
#creating bar chart on the grouped data
plt.xlabel('Gender')
plt.ylabel('Number of passengers')