aadarsh
aadarsh
Code :-
import pandas as pd
#Create Dataframe
df = pd.DataFrame(data)
df
Output :-
Code :-
# Selection using loc() - selecting rows and columns by labels
print("Selection using loc():")
Output :-
Code :-
# Selection using iloc() - selecting rows and columns by index positions
print("Selection using iloc():")
Output :-
Practical – 2
Code :-
import pandas as pd
Output :-
Practical – 3
Ques. Write a program to fill all missing values in a DataFrame with zero
Code :-
import pandas as pd
#Create DataFrame
df = pd.DataFrame(data)
Output:-
Practical – 4
Code :-
import pandas as pd
#Sample DataFrame
df1 = pd.DataFrame({
'A':[1,2,3],
'B':['a','b','c']
})
df2 = pd.DataFrame({
'A':[4,5,6],
'B':['d','e','f']
})
Output:-
Code :-
#Sample DataFrame
df3 = pd.DataFrame({
'A': [1, 2, 3],
'C': ['x', 'y', 'z']
})
df4 = pd.DataFrame({
'D': ['p', 'q', 'r']},
index=[1, 2, 3])
Output:-
Code :-
# Sample DataFrames for merge()
df5 = pd.DataFrame({
'A': [1, 2, 3],
'B': ['a', 'b', 'c'],
'Key': ['K1', 'K2', 'K3']
})
df6 = pd.DataFrame({
'C': ['x', 'y', 'z'],
'D': ['p', 'q', 'r'],
'Key': ['K1', 'K2', 'K3']
})
Output:-
Practical – 5
Ques. Write a program to draw bar graph for the following data for the Medal
tally of CWG-2018:-
Gold Silver Bronze Total
26 20 20 66
Code :-
import matplotlib.pyplot as plt
# Data
medals = ['Gold', 'Silver', 'Bronze', 'Total']
counts = [26, 20, 20, 66]
# Show plot
plt.show()
Output:-
Practical – 6
Ques. Implementing Line plot, Dist plot, Lmplot, Count plot using Seaborn
library
Code :-
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Sample data
data = pd.DataFrame({
'x': range(1, 11),
'y': [3, 5, 7, 4, 6, 8, 5, 9, 7, 10],
'category': ['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B']
})
# Line plot
plt.figure(figsize=(8, 5))
sns.lineplot(x='x', y='y', data=data)
plt.title('Line Plot')
plt.show()
Output:-
Code :-
# Dist plot
plt.figure(figsize=(8, 5))
sns.distplot(data['y'], kde=False, bins=5)
plt.title('Distribution Plot')
plt.show()
Output:-
Code :-
# Lmplot
plt.figure(figsize=(8, 5))
sns.lmplot(x='x', y='y', data=data, hue='category')
plt.title('Lmplot')
plt.show()
Output:-
Code :-
# Count plot
plt.figure(figsize=(8, 5))
sns.countplot(x='category', data=data)
plt.title('Count Plot')
plt.show()
Output:-
Practical – 7
Code :-
import pandas as pd
aid = pd.DataFrame(aid_data)
Output:-
Code :-
# Displaying aid for Shoes only
shoes_aid = aid[['NGO', 'State', 'Shoes']]
print("\nAid for Shoes only:")
shoes_aid
Output:-
Practical – 8
Ques. Create a DataFrame ndf having Name, Gender, Position, City, Age,
Projects. Write a program to summarize how many projects are being handled
by each position for each city?
Code :-
import pandas as pd
ndf = pd.DataFrame(data)
# Summarizing the number of projects by each position for each city using
pivot_table
summary = pd.pivot_table(ndf, index=['Position', 'City'], values='Projects',
aggfunc='sum')
Output:-
Practical – 9
Ques. Marks is a list that stores marks of a student in 10 unit test. Write a
program to plot Line chart for the student’s performance in these 10 test
Code :-
import matplotlib.pyplot as plt
Output:-
Practical – 10
Ques. Write a program to plot a horizontal bar chart from the height of some
students
Code :-
import matplotlib.pyplot as plt
Output:-
Practical – 11
Code :-
import scipy.stats as stats
# Sample data
group1 = [25, 30, 35, 40, 45]
group2 = [20, 22, 25, 28, 30]
group3 = [15, 18, 20, 22, 25]
# Print results
print("F-statistic:", f_statistic)
print("P-value:", p_value)
# Interpret results
alpha = 0.05
if p_value < alpha:
print("Reject null hypothesis: There is a significant difference between
group means.")
else:
print("Fail to reject null hypothesis: There is no significant difference
between group means.")
Output:-
Practical – 12
Code :-
import numpy as np
import matplotlib.pyplot as plt
Output:-
Practical – 13
Code :-
import numpy as np
# Calculate covariance
covariance = np.mean((x - mean_x) * (y - mean_y))
Output:-
Practical – 14
Ques. Create a GUI based form for admission purpose for your college
Code :-
import tkinter as tk
from tkinter import messagebox
def submit_form():
name = name_entry.get()
age = age_entry.get()
gender = gender_var.get()
course = course_var.get()
# Labels
tk.Label(root, text="Name:").grid(row=0, column=0, padx=10, pady=5)
tk.Label(root, text="Age:").grid(row=1, column=0, padx=10, pady=5)
tk.Label(root, text="Gender:").grid(row=2, column=0, padx=10, pady=5)
tk.Label(root, text="Course:").grid(row=3, column=0, padx=10, pady=5)
# Entry fields
name_entry = tk.Entry(root)
name_entry.grid(row=0, column=1, padx=10, pady=5)
age_entry = tk.Entry(root)
age_entry.grid(row=1, column=1, padx=10, pady=5)
# Submit button
submit_btn = tk.Button(root, text="Submit", command=submit_form)
submit_btn.grid(row=4, column=0, columnspan=2, pady=10)
root.mainloop()
Output:-
Practical – 15
Ques. Create a GUI based form for admission purpose for your college
Code :-
import tkinter as tk
from tkinter import messagebox
import sqlite3
def submit_form():
try:
conn = sqlite3.connect("college_admission.db")
conn.execute('''CREATE TABLE IF NOT EXISTS admission_form
messagebox.showerror("Error", str(e))
root = tk.Tk()
root.title("College Admission Form")
root.mainloop()
Output:-