Group A

Q8: Data Visualization I 1. Use the inbuilt dataset 'titanic'. The dataset contains 891 rows and contains information about the passengers who boarded the unfortunate Titanic ship. Use the Seaborn library to see if we can find any patterns in the data. 2. Write a code to check how the price of the ticket (column name: 'fare') for each passenger is distributed by plotting a histogram.

Data Visualization I

Solution and implementation for Q8 from Data Science Laboratory (ds).

8_data_visualization_1.py Download
import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset("titanic")
print(df.head())

# Count of survival (0 = died, 1 = survived)
sns.countplot(x="survived", data=df)
plt.title("Survival Count")
plt.show()

# Survival based on gender
sns.countplot(x="survived", hue="sex", data=df)
plt.title("Survival based on Gender")
plt.show()

# Histogram of Fare
plt.hist(df["fare"], bins=20)
plt.title("Fare Distribution")
plt.xlabel("Fare")
plt.ylabel("Number of Passengers")
plt.show()

Other Questions in Data Science Laboratory

See All Available Questions
Download