Analyzing Survivors Based on Gender

Load the Titanic dataset from seaborn’s built-in dataset collection and plot a bar chart showcasing the number of survivors based on gender.

Example Output:

Utilize seaborn’s countplot method, and you can load the Titanic dataset using sns.load_dataset('titanic').

import seaborn as sns
import matplotlib.pyplot as plt

def plot_titanic_survivors():
    titanic_data = sns.load_dataset('titanic')
    sns.countplot(x='sex', hue='survived', data=titanic_data)
    plt.title('Survivors based on Gender in Titanic')
    plt.show()

plot_titanic_survivors()

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!