Data Science Lab using Python – PCC DS391
This document contains all 10 experiments as per the syllabus for Semester III [Link] in
Data Science.
Experiment 1: Interactive commands in Python
🔹 Objective:
Write simple Python programs for reading/writing files and basic operations.
🔹 Code:
# Example: File I/O
with open('[Link]', 'w') as f:
[Link]("Hello, Data Science Lab!")
Experiment 2: Familiarization with IDE in Python
🔹 Objective:
Get familiar with Jupyter Notebook / VS Code for writing and running Python programs.
🔹 Code:
> Try: Shortcut keys, Markdown + Code, variable watching.
Experiment 3: Standard sorting/searching algorithms
🔹 Objective:
Implement standard sorting/searching algorithms in Python.
🔹 Code:
# Bubble Sort Example
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
Experiment 4: Plotting data using charts
🔹 Objective:
Use matplotlib to create line, bar, and pie charts.
🔹 Code:
import [Link] as plt
x = ['A', 'B', 'C']
y = [10, 20, 15]
[Link](x, y)
[Link]('Bar Chart')
[Link]()
Experiment 5: Exploratory Data Analysis (EDA)
🔹 Objective:
Use pandas and statistics for mean, std, var.
🔹 Code:
import pandas as pd
data = {'A': [10, 20, 30, 40]}
df = [Link](data)
print("Mean:", df['A'].mean())
print("Std Dev:", df['A'].std())
Experiment 6: Plotting distributions
🔹 Objective:
Plot histograms, boxplots, KDEs using seaborn.
🔹 Code:
import seaborn as sns
[Link](df['A'], kde=True)
Experiment 7: Support Vector Machine (SVM)
🔹 Objective:
Classify data using Support Vector Machine from scikit-learn.
🔹 Code:
from sklearn import datasets
from sklearn.model_selection import train_test_split
from [Link] import SVC
iris = datasets.load_iris()
X_train, X_test, y_train, y_test = train_test_split([Link], [Link], test_size=0.2)
model = SVC()
[Link](X_train, y_train)
print("Accuracy:", [Link](X_test, y_test))
Experiment 8: K-means Clustering
🔹 Objective:
Use k-means for data clustering and visualize results.
🔹 Code:
from [Link] import KMeans
import [Link] as plt
kmeans = KMeans(n_clusters=3)
[Link]([Link])
[Link]([Link][:, 0], [Link][:, 1], c=kmeans.labels_)
[Link]("K-Means Clustering")
[Link]()
Experiment 9: Graphs for social networks
🔹 Objective:
Use networkx to create and visualize a basic graph.
🔹 Code:
import networkx as nx
G = [Link]()
G.add_edges_from([('A', 'B'), ('B', 'C'), ('C', 'A')])
[Link](G, with_labels=True)
Experiment 10: Centrality & PageRank
🔹 Objective:
Calculate graph metrics like centrality and PageRank.
🔹 Code:
print("Degree Centrality:", nx.degree_centrality(G))
print("PageRank:", [Link](G))