import matplotlib.pyplot as plt
import seaborn as sns
# Create a count plot of the Pclass column
plt.figure(figsize=(7, 5))
sns.countplot(data=train_data, x='Pclass', palette='viridis')
plt.title('Passenger Count by Passenger Class')
plt.xlabel('Passenger Class')
plt.ylabel('Number of Passengers')
# Optional: Add labels for better readability
# plt.xticks([0, 1, 2], ['First Class', 'Second Class', 'Third Class'])
plt.show()
In this analysis, we explored how passengers were distributed among different classes on the Titanic. We used the Pclass column, which represents passenger class (1st, 2nd, and 3rd), to understand how many people traveled in each. Using Seaborn’s countplot, we visualized the data to show the number of passengers in each class. The bar chart revealed that most passengers were in the third class, followed by the first and second classes. This step is part of data analysis and wrangling, helping us understand the dataset’s structure and identify which passenger groups were most common. Such insights are useful later when preparing and training a machine learning model to predict survival chances based on class.