Docsity

BCA DATA VISUALIZATION LAB ASSIGNMENT WITH PYTHON CODE AND CHARTS, Assignments of Computer Science

Toggle sidebar
bg1
Assignment:- 01 Date:-23/07/26
1.Create a Bar Chart to compare the marks of 10 students in five different subjects.
Input:-
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Synthetic data for 10 students and 5 subjects
np.random.seed(42)
data = np.random.randint(40, 100, size=(10, 5))
students = [f'Student {i+1}' for i in range(10)]
subjects = ['Math', 'Science', 'English', 'History', 'Computer']
df = pd.DataFrame(data, index=students, columns=subjects)
# Plotting
df.plot(kind='bar', figsize=(12, 6), colormap='viridis')
plt.title('Marks of 10 Students in 5 Different Subjects')
plt.xlabel('Students')
plt.ylabel('Marks')
plt.legend(title='Subjects', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download BCA DATA VISUALIZATION LAB ASSIGNMENT WITH PYTHON CODE AND CHARTS and more Assignments Computer Science in PDF only on Docsity!

1.Create a Bar Chart to compare the marks of 10 students in five different subjects. Input:- import pandas as pd import matplotlib.pyplot as plt import numpy as np

Synthetic data for 10 students and 5 subjects

np.random.seed(42) data = np.random.randint(40, 100, size=(10, 5)) students = [f'Student {i+1}' for i in range(10)] subjects = ['Math', 'Science', 'English', 'History', 'Computer'] df = pd.DataFrame(data, index=students, columns=subjects)

Plotting

df.plot(kind='bar', figsize=(12, 6), colormap='viridis') plt.title('Marks of 10 Students in 5 Different Subjects') plt.xlabel('Students') plt.ylabel('Marks') plt.legend(title='Subjects', bbox_to_anchor=(1.05, 1), loc='upper left') plt.xticks(rotation=45) plt.tight_layout() plt.show()

OUTPUT

Teacher’s Signature:-……………………………..

Output Teacher’s Signature:-……………………………..

  1. Create a Pie Chart showing the percentage distribution of a monthly household budget. Input:- import matplotlib.pyplot as plt categories = ['Rent', 'Groceries', 'Utilities', 'Entertainment', 'Savings'] budget = [30, 25, 15, 10, 20] # Percentages colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99', '#c2c2f0'] plt.figure(figsize=(7, 7)) plt.pie(budget, labels=categories, colors=colors, autopct='%1.1f%%', startangle=140, shadow=True) plt.title('Percentage Distribution of Monthly Household Budget') plt.show()
  1. Generate a Histogram for the age distribution of 100 employees and interpret the result. Input:- import matplotlib.pyplot as plt import numpy as np

Generate random ages for 100 employees (between 22 and 60)

np.random.seed(0) ages = np.random.randint(22, 61, 100) plt.figure(figsize=(8, 5)) plt.hist(ages, bins=10, color='skyblue', edgecolor='black') plt.title('Age Distribution of 100 Employees') plt.xlabel('Age') plt.ylabel('Number of Employees') plt.show()

Interpretation printed as output

print("Interpretation:") print("The histogram shows the frequency of employees across different age groups.") print("It helps identify which age ranges have the highest or lowest number of employees in the company.")

Output Teacher’s Signature:-……………………………..

Output Teacher’s Signature:-……………………………

  1. Create a Box Plot for the Sepal Width feature of the Iris dataset and identify any outliers. Input:- import seaborn as sns import matplotlib.pyplot as plt

Load the built-in Iris dataset

iris = sns.load_dataset('iris')

Create Box Plot for Sepal Width

plt.figure(figsize=(8, 5)) sns.boxplot(x=iris['sepal_width'], color='lightgreen') plt.title('Box Plot of Sepal Width in Iris Dataset') plt.xlabel('Sepal Width (cm)') plt.show()

Identifying outliers

print("Outlier Identification:") print("The individual dots located outside the 'whiskers' on either side of the box plot represent the outliers for the Sepal Width feature.")

7.Using the Titanic dataset, create a Count Plot showing the number of male and female passengers. Input:- import seaborn as sns import matplotlib.pyplot as plt

Load the built-in Titanic dataset

titanic = sns.load_dataset('titanic')

Create Count Plot

plt.figure(figsize=(7, 5)) sns.countplot(data=titanic, x='sex', hue='sex', palette='Set2', legend=False) plt.title('Number of Male and Female Passengers on Titanic') plt.xlabel('Gender') plt.ylabel('Passenger Count') plt.show()

Output Teacher’s Signature:-……………………………..

Output Teacher’s Signature:-……………………………..

  1. Load the California Housing dataset and create a Scatter Plot showing the relationship between Median Income and Median House Value. Input:- import matplotlib.pyplot as plt from sklearn.datasets import fetch_california_housing import pandas as pd

Load the California Housing dataset

california = fetch_california_housing(as_frame=True) df = california.frame

Create a Scatter Plot

plt.figure(figsize=(10, 6)) plt.scatter(df['MedInc'], df['MedHouseVal'], alpha=0.4, color='teal', s=15) plt.title('Relationship between Median Income and Median House Value') plt.xlabel('Median Income (in Tens of Thousands of USD)') plt.ylabel('Median House Value (in Hundreds of Thousands of USD)') plt.grid(True, linestyle='--', alpha=0.5) plt.show()

  1. Create a Pair Plot for the Iris dataset and identify the class separation among different species. Input:- import seaborn as sns import matplotlib.pyplot as plt

Load the built-in Iris dataset

iris = sns.load_dataset('iris')

Create a Pair Plot

sns.pairplot(iris, hue='species', palette='husl', markers=["o", "s", "D"]) plt.suptitle('Pair Plot of Iris Dataset by Species', y=1.02) plt.show()

Identifying class separation

print("Class Separation Identification:") print("- The 'setosa' species (usually the blue cluster) is highly distinct and easily separable from the other two species across almost all feature combinations.") print("- 'versicolor' and 'virginica' show some overlap, particularly in sepal length and sepal width, making them harder to separate completely.") print("- However, using Petal Length and Petal Width, 'versicolor' and 'virginica' can be separated much more clearly.")

Output Teacher’s Signature:-……………………………..