This code makes a plot showing deaths according to sex (gender)
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load the training data (assuming titanic_df is already loaded from previous cells)
# If not loaded, uncomment the line below:
# titanic_df = pd.read_csv('train.csv')
# Create a bar plot of survival count by sex
plt.figure(figsize=(8, 6))
sns.countplot(data=titanic_df, x='Sex', hue='Survived', palette='viridis')
plt.title('Survival Count by Sex', fontsize=14)
plt.xlabel('Sex', fontsize=12)
plt.ylabel('Count', fontsize=12)
plt.legend(title='Survived', title_fontsize=12)
plt.grid(axis='y', linestyle='--', alpha=0.6) # Add grid lines on y-axis
plt.show()
This code makes a plot showing deaths according to embarkment
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load the training data (assuming titanic_df is already loaded from previous cells)
# If not loaded, uncomment the line below:
# titanic_df = pd.read_csv('train.csv')
# Create a bar plot of survival count by embarkment point
plt.figure(figsize=(8, 6))
sns.countplot(data=titanic_df, x='Embarked', hue='Survived', palette='viridis')
plt.title('Survival Count by Embarkment Point', fontsize=14)
plt.xlabel('Embarkment Point', fontsize=12)
plt.ylabel('Count', fontsize=12)
plt.legend(title='Survived', title_fontsize=12)
plt.grid(axis='y', linestyle='--', alpha=0.6) # Add grid lines on y-axis
plt.show()
This code makes a plot showing deaths according to SibSp (siblings or spouses aboard)
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load the training data (assuming titanic_df is already loaded from previous cells)
# If not loaded, uncomment the line below:
# titanic_df = pd.read_csv('train.csv')
# Create a bar plot of survival count by SibSp
plt.figure(figsize=(10, 6))
sns.countplot(data=titanic_df, x='SibSp', hue='Survived', palette='viridis')
plt.title('Survival Count by Number of Siblings/Spouses Aboard (SibSp)', fontsize=14)
plt.xlabel('Number of Siblings/Spouses Aboard (SibSp)', fontsize=12)
plt.ylabel('Count', fontsize=12)
plt.legend(title='Survived', title_fontsize=12)
plt.grid(axis='y', linestyle='--', alpha=0.6) # Add grid lines on y-axis
plt.show()
This code makes a plot showing deaths according to parch (parents or children aboard)
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Load the training data
# Assuming the training data is in a file named 'train.csv'
try:
titanic_df = pd.read_csv('train.csv')
except FileNotFoundError:
print("Error: 'train.csv' not found. Please make sure the file is in the correct directory.")
# You might want to add a way for the user to upload the file here.
# Create a bar plot of survival count by Parch
plt.figure(figsize=(10, 6))
sns.countplot(data=titanic_df, x='Parch', hue='Survived', palette='viridis')
plt.title('Survival Count by Number of Parents/Children Aboard (Parch)', fontsize=14)
plt.xlabel('Number of Parents/Children Aboard (Parch)', fontsize=12)
plt.ylabel('Count', fontsize=12)
plt.legend(title='Survived', title_fontsize=12)
plt.grid(axis='y', linestyle='--', alpha=0.6) # Add grid lines on y-axis
plt.show()