0% found this document useful (0 votes)
6 views30 pages

IP Practicals

The document contains a series of programming tasks involving Python and SQL, including creating DataFrames, generating charts, and manipulating SQL tables. It provides code examples for creating and modifying data structures, as well as SQL commands for creating tables, inserting data, and querying information. Each part of the document is divided into sections labeled Part A, B, and C, with specific tasks and corresponding code outputs.

Uploaded by

Umesh Durbaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views30 pages

IP Practicals

The document contains a series of programming tasks involving Python and SQL, including creating DataFrames, generating charts, and manipulating SQL tables. It provides code examples for creating and modifying data structures, as well as SQL commands for creating tables, inserting data, and querying information. Each part of the document is divided into sections labeled Part A, B, and C, with specific tasks and corresponding code outputs.

Uploaded by

Umesh Durbaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Part A

1. Write python code for the following with respect to DataFrame marks, 3M

(i) Write the code to create dataframe marks


(ii) Display first two rows.
(iii) Add a new column called Total which is sum of all Tests.

Part B
2. Write program in python to create a line chart with the given data
and also set the name to . x-axis as ename, y axis as sal, title as
simple. Also save graph as simple.pdf
ename=[‘Hari’,’Riya’,’Chandhan’,’Joe’,’Mita’]
sal=[4000,6000,5000,3500,8000] 5M

Part C
3. Write a SQL Command to do the following 7M
i. create a table called products based on the following given data.
Columns/Field Datatype Key
Pid Int Primary key
Pname Varchar(20)
Category Varchar(15)
Stock Int
Comm Decimal(6,2)
Mfgdate date
ii. insert the following data into the products table as
(1,'Phone','Electronics',35000,350.23,'2024-09-27')
(2,'Shoe','Apparel',2500,200.45,'2023-10-15')
(3,'Chair','Home',4400,40.23,'2024-11-22')
iii. Display first two characters in every product name
iv. Display product name by deleting leading/trailing spaces if there are any
v. Display the position of ‘nic’ in product category
vi. Display product names and category manufactured in February month
vii. Display all products manufactured month name

Page 1 of 8
import pandas as pd
# Creating the DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Test1': [85, 92, 78],
'Test2': [88, 94, 82],
'Test3': [90, 89, 84]
}
marks = pd.DataFrame(data)
print(marks)
print()
print(marks.head(2))
print()
marks['Total'] = marks['Test1'] + marks['Test2'] + marks['Test3']
print(marks)

Output
Name Test1 Test2 Test3
0 Alice 85 88 90
1 Bob 92 94 89
2 Charlie 78 82 84

Name Test1 Test2 Test3


0 Alice 85 88 90
1 Bob 92 94 89

Page 2 of 8
Name Test1 Test2 Test3 Total
0 Alice 85 88 90 263
1 Bob 92 94 89 275
2 Charlie 78 82 84 244

import matplotlib.pyplot as plt


ename = ['Hari', 'Riya', 'Chandhan', 'Joe', 'Mita']
sal = [4000, 6000, 5000, 3500, 8000]
plt.plot(ename, sal, marker='o')
plt.xlabel('ename')
plt.ylabel('sal')
plt.title('simple')
plt.savefig('simple.pdf')
plt.show()
Output

Page 3 of 8
1.CREATE TABLE products (
Pid INT PRIMARY KEY,
Pname VARCHAR(20),
Category VARCHAR(15),
Stock INT,
Comm DECIMAL(6,2),
Mfgdate DATE
);
2. INSERT INTO products VALUES
(1, 'Phone', 'Electronics', 35000, 350.23, '2024-09-27');
INSERT INTO products VALUES
(2, 'Shoe', 'Apparel', 2500, 200.45, '2023-10-15');
INSERT INTO products VALUES
(3, 'Chair', 'Home', 4400, 40.23, '2024-11-22');
3. SELECT SUBSTRING(Pname, 1, 2) AS FirstTwoCharacters FROM products;
4. SELECT TRIM(Pname) AS TrimmedProductName FROM products;
5. SELECT INSTR(Category, 'nic') AS PositionOfNic FROM products;
6. SELECT Pname, Category FROM products
WHERE MONTH(Mfgdate) = 2;
7. SELECT Pname, Category, DATE_FORMAT(Mfgdate, '%M') AS ManufacturedMonth
FROM products;

Output
1&2
Pid Pname Category Stock Comm Mfgdate
1 Phone Electronics 35000 350.23 2024-09-27
2 Shoe Apparel 2500 200.45 2023-10-15
3 Chair Home 4400 40.23 2024-11-22

Page 4 of 8
3. FirstTwoCharacters
Ph
Sh
Ch
4.TrimmedProductName
Phone
Shoe
Chair
5.PositionOfNic
8
0
0
6. Empty set

7.Pname Category ManufacturedMonth


Phone Electronics September
Shoe Apparel October
Chair Home November

PART A
1. Consider the following Series Class and answer the questions.

A 45
B 36
C 27
D 35
(i) Write python code to create above series Class using list
(ii) Write a statement to delete element whose index is ‘B’

Page 5 of 8
(iii) Write a statement to add one element with 54 as value and index as ‘E’ 3M

PART B
2. Write program in python to create a bar chart that represents ATTENDANCE COUNT
of classes from 8 to 12, and also set the name to x-axis as class, y-axis as count and
title as 'Classs wise ATTENDANCE COUNT’. Also save graph as simple.pdf.
Class=[8,9,10,11,12]
ATTENDANCE COUNT=[35,30,40,45,42]
5M
PART C
3.Consider the following table Department, and write SQL commands to the following
7M

i. Create Department table as per given data

primary key on Deptno column


ii. Insert data[10,CS,Riya][20,AI,Shyam,][30,ML,Ananya],[40,CN,Hari]
into Department table
iii. Display department name and their HOD name who are working in CS department
iv Display deptname and their deptno whose HOD is Riya
v. Display deptno from Department table
vii.Display deptno whose HOD name starts with letter ‘A’
viii.Add one more column in the name of salary

ANSWERS
1. import pandas as pd

# Creating the Series using a list and specifying the index


data = [45, 36, 27, 35]
index = ['A', 'B', 'C', 'D']
series = pd.Series(data, index=index)
print(series)
# Deleting the element with index 'B'
series = series.drop('B')
print(series)
Page 6 of 8
# Adding a new element with value 54 and index 'E'
series['E'] = 54
print(series)

OUTPUT

A 45
B 36
C 27
D 35
dtype: int64
A 45
C 27
D 35
dtype: int64
A 45
C 27
D 35
E 54
dtype: int64

2. Answer
import matplotlib.pyplot as plt
import numpy as np
# Data
classes = [8, 9, 10, 11, 12]
attendance_count = [35, 30, 40, 45, 42]
# Create the bar chart
result = plt.bar(classes, attendance_count, label='Attendance Count')
# Set the labels and title
plt.xlabel('Class')
plt.ylabel('Count')
plt.title('Class wise ATTENDANCE COUNT')
# Save the graph as PDF
plt.savefig('simple.pdf')
# Display the plot
plt.show()

Page 7 of 8
Output

3. Answer

1. CREATE TABLE Department ( Deptno INT PRIMARY KEY, Deptname VARCHAR(20),


HODname VARCHAR(30) );
2. INSERT INTO Department (Deptno, Deptname, HODname) VALUES (40, 'cn', 'hari'), (20,
'AI', 'shyam'), (30, 'ML', 'Ananya');
select * from Department;
3.SELECT Deptname, HODname FROM Department WHERE Deptname = 'CS';
4. SELECT Deptname, Deptno FROM Department WHERE HODname = 'Riya';
5. SELECT Deptno FROM Department;
6. SELECT Deptno FROM Department WHERE HODname LIKE 'A%';
7. ALTER TABLE Department ADD COLUMN salary DECIMAL(10,2);

Output

Deptno Deptname HODname


20 AI shyam
30 ML Ananya
40 cn hari
Deptno
20
30
40
Deptno
30

Page 8 of 8
3a) Consider the following Series Class and answer the questions. 3M
A 45
B 36
C 27
D 35
(i) Write python code to create above series Class using list
(ii) Write a statement to delete element whose index is ‘B’
(iii) Write a statement to add one element with 54 as value and index as ‘E’

3b) Write program in python to create a line chart with the given data and also set the name
to x-axis, y- axis and title. Also save graph as simple.pdf. 5M
ename=[‘Hari’,’Riya’,’Chandhan’,’Joe’,’Mita’]
sal=[4000,6000,5000,3500,8000]

3.c) Consider the following table and write SQL commands for all the questions 7M

i. Create a new database in the name of “practicals” and


to select the database “practicals”
ii. To create above table
iii. Insert all the rows
iv. Display the garment names whose available quantity is 20 or more

v. Increase all garment price by 10%


vi. Display the garment details whose readydate is not given.
vii. Delete all the details of garment whose gcode is 12345
Answers
3a. import pandas as pd
# Creating the series using a list
data = [45, 36, 27, 35]
index = ['A', 'B', 'C', 'D']
series = pd.Series(data, index)
print(series)
# Deleting the element with index 'B'
series = series.drop('B')
print(series)
# Adding an element with value 54 and index 'E'
series['E'] = 54
print(series)

Output
A 45
B 36
C 27
D 35
dtype: int64
A 45
C 27
D 35
dtype: int64

3.b Answers
import matplotlib.pyplot as plt
# Data
ename = ['Hari', 'Riya', 'Chandhan', 'Joe', 'Mita']
sal = [4000, 6000, 5000, 3500, 8000]
# Create a line chart
plt.plot(ename, sal, marker='o')
# Set names for x-axis, y-axis, and title
plt.xlabel('Employee Name')
plt.ylabel('Salary')
plt.title('Employee Salaries')
# Save the graph as simple.pdf
plt.savefig('simple.pdf')
# Show the plot
plt.show()

OUTPUT

3.C
i. CREATE DATABASE practicals;
USE practicals;
ii. CREATE TABLE Garments ( Gcode int,GarmentName VARCHAR(50), AvailableQuantity INT,
Price DECIMAL(10, 2), ReadyDate DATE);
iii.

iv. SELECT GarmentName FROM Garments WHERE AvailableQuantity >= 20


v. UPDATE Garments SET Price = Price * 1.10;
vi. SELECT * FROM Garments WHERE ReadyDate IS NULL;
vii. DELETE FROM Garments WHERE gcode = 12345;
SELECT * FROM Garments;
Gcode GarmentName AvailableQuantity Price ReadyDate
10023 Pencil skirt 1150 2 5.00 2010-12-19
10001 Formal skirt 1250 25.00 2010-01-12
10012 Baby Top 750 20.00 2009-04-09
10009 Informal Pant 1500 35.00 2012-12-20
10020 Frock 850 20.00 2012-01-01
10089 Slacks 750 10.00 2010-10-31
IV
GarmentName
Pencil skirt
Formal skirt
Baby Top
Informal Pant
Frock
Slacks
v.
Gcode GarmentName AvailableQuantity Price ReadyDate
10023 Pencil skirt 1150 27.50 2010-12-19
10001 Formal skirt 1250 27.50 2010-01-12
10012 Baby Top 750 22.00 2009-04-09
10009 Informal Pant 1500 38.50 2012-12-20
10020 Frock 850 22.00 2012-01-01
10089 Slacks 750 11.00 2010-10-31
vi. Empty Set
vii
Gcode GarmentName AvailableQuantity Price ReadyDate
10023 Pencil skirt 1150 27.50 2010-12-19
10001 Formal skirt 1250 27.50 2010-01-12
10012 Baby Top 750 22.00 2009-04-09
10009 Informal Pant 1500 38.50 2012-12-20
10020 Frock 850 22.00 2012-01-01
10089 Slacks 750 11.00 2010-10-31

4a) Write python code to create the following DataFrame cars using list of dictionary method.3M

4b) Write program in python to create a histogram that represents runs of batman in different
matches in the form of ranges, and also set the name to x-axis, y-axis and title. Also save
graph as simple.pdf. 5M
runs=[81,85,65,42,57,72,85,99,94,72,66,67,76]
bins=[50,60,70,80,90,100]
4c)Consider the following table and write SQL commands for all the questions 7M
Table Name: STUDENT
ROLLNO NAME DOB CITY STREAM FEE
1 Srinath 2015-11-05 Bangalore Science 2344.75
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89

i. Create above table by applying primary key on Rollno column.


ii. Insert above data to the table.
iii. Display details of all the students based on stream.
iv. Display total number of students in each stream.
v. Display student names who born in the year 2015.
vi. Display 4 characters starts from 3rd character in all student names.
vii. Display sum of fees of all the students.

ANSWERS
4.a
import pandas as pd
d={'Mode':['Samurai','Accord','CR-
V','Nexon'],'Brand':['Suzuki','Honda','Honda','Tata'],'Make':[1993,1997,1997,2021]}
a=pd.DataFrame(d)
print(a)

OUTPUT

Mode Brand Make


0 Samurai Suzuki 1993
1 Accord Honda 1997
2 CR-V Honda 1997
3 Nexon Tata 2021

4.b

import matplotlib.pyplot as plt

# Data
runs = [81, 85, 65, 42, 57, 72, 85, 99, 94, 72, 66, 67, 76]
bins = [50, 60, 70, 80, 90, 100]

# Create a histogram
plt.hist(runs, bins=bins, edgecolor='black')

# Set names for x-axis, y-axis, and title


plt.xlabel('Runs')
plt.ylabel('Number of Matches')
plt.title('Histogram of Batman Runs in Different Matches')

# Save the graph as simple.pdf


plt.savefig('simple.pdf')

# Show the plot


plt.show()

output

4.c

i. CREATE TABLE STUDENT (


ROLLNO INT PRIMARY KEY,
NAME VARCHAR(50),
DOB DATE,
CITY VARCHAR(50),
STREAM VARCHAR(50),
FEE DECIMAL(10, 2)
);
ii. INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES
(1, 'Srinath', '2015-11-05', 'Bangalore', 'Science', 2344.75);
. INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (2,
'Supriya', '2016-09-25', 'Nagpur', 'Humanities', 5454.50);
. INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (3,
'Chandhan', '2018-12-18', 'Delhi NCR', 'Arts', 1234.56);
. INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (4, 'Giri',
'2012-12-12', 'Hyderabad', 'Science', 8746.89);
. INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (5,
'Kaveri', '2015-02-18', 'Chennai', 'Science', 8746.89);
iii. SELECT STREAM, COUNT(*) AS TotalStudents FROM STUDENT
GROUP BY STREAM;
Iv SELECT STREAM, COUNT(*) AS TotalStudents FROM STUDENT
GROUP BY STREAM;
v. SELECT NAME FROM STUDENT WHERE YEAR(DOB) = 2015;

vi. SELECT SUBSTRING(NAME, 3, 4) AS PartialName FROM STUDENT;

vii. SELECT SUM(FEE) AS TotalFees FROM STUDENT;

output

4. iii STREAM TotalStudents


Science 3
Humanities 1
Arts 1

Iv STREAM TotalStudents
Science 3
Humanities 1
Arts 1

v. NAME
Srinath
Kaveri

Vi PartialName
inat
priy
andh
ri
veri

vii. TotalFees
26527.59
5a) Write python code to create the following DataFrame emp , and write python
statements to answer the questions from (i) to (iii). 3M

(i) Add a new column called Dept with values ['Maths','Phy','Chem','Comp','Phy']


(ii) Add a new column called HRA (HRA is 10% of Salary)
(iii) Delete a column called Total.

5b) Write program in python to create a line chart with the given data and also set the name to
x-axis, y- axis and title. Also save graph name as simple.pdf. 5M
ename=[‘Hari’,’Riya’,’Chandhan’,’Joe’,’Mita’]
sal=[4000,6000,5000,3500,8000]

5c) Consider the following table and write SQL commands for all the questions 7M
Table Name: STUDENT
ROLLNO NAME DOB CITY STREAM FEE
1 Srinath 2015-11-05 Bangalore Science 2344.75
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89

i. Create above table by applying primary key on Rollno column.


ii. Insert above data to the table.
iii. Display details of all the students based on stream.
iv. Display total price of all Science stream students.
v. Display student names and city who born in December month.
vi. Display last two characters in every Student name.
vii. Round Off Fees without decimal digits.

Answers

5.a

import pandas as pd
a={'Name':['Anya','Smith','Bina','Vinay','Arjun'],'Job':['Clerk','Analyst','Analyst','Clerk','Salesman'],'S
al':[500,550,480,475,540]}
b=pd.DataFrame(a)
print(b)
# (i) Add a new column called Dept
b['Dept'] = ['Maths', 'Phy', 'Chem', 'Comp', 'Phy']

# (ii) Add a new column called HRA (10% of Salary)


b['HRA'] = b['Sal'] * 0.10

# (iii) Delete a column called Total (if it existed)


if 'Total' in b.columns:
b.drop('Total', axis=1, inplace=True)

print(b)

Output

Name Job Sal


0 Anya Clerk 500
1 Smith Analyst 550
2 Bina Analyst 480
3 Vinay Clerk 475
4 Arjun Salesman 540

Name Job Sal Dept HRA


0 Anya Clerk 500 Maths 50.0
1 Smith Analyst 550 Phy 55.0
2 Bina Analyst 480 Chem 48.0
3 Vinay Clerk 475 Comp 47.5
4 Arjun Salesman 540 Phy 54.0

5.b

import matplotlib.pyplot as plt


# Data
ename = ['Hari', 'Riya', 'Chandhan', 'Joe', 'Mita']
sal = [4000, 6000, 5000, 3500, 8000]
# Create a line chart
plt.plot(ename, sal, marker='o')
# Set x-axis and y-axis labels
plt.xlabel('Employee Name')
plt.ylabel('Salary')
# Set the title
plt.title('Employee Salaries')
# Save the graph as a PDF file
plt.savefig('simple.pdf')
# Show the plot (optional)
plt.show()
5.c
i. CREATE TABLE Students (
ROLLNO INT PRIMARY KEY,
NAME VARCHAR(50),
DOB DATE,
CITY VARCHAR(50),
STREAM VARCHAR(50),
FEE DECIMAL(10, 2)
);

ii.INSERT INTO Students (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES
(1, 'Srinath', '2015-11-05', 'Bangalore', 'Science', 2344.75),
(2, 'Supriya', '2016-09-25', 'Nagpur', 'Humanities', 5454.50),
(3, 'Chandhan', '2018-12-18', 'Delhi NCR', 'Arts', 1234.56),
(4, 'Giri', '2012-12-12', 'Hyderabad', 'Science', 8746.89),
(5, 'Kaveri', '2015-02-18', 'Chennai', 'Science', 8746.89);

iii. SELECT * FROM Students ORDER BY STREAM;


iv. SELECT SUM(FEE) AS Total_Science_Fee FROM Students
WHERE STREAM = 'Science';
v. SELECT NAME, CITY FROM Students
WHERE MONTH(DOB) = 12;

vi. SELECT NAME, RIGHT(NAME, 2) AS Last_Two_Characters


FROM Students;

vii. SELECT ROLLNO, NAME, DOB, CITY, STREAM, ROUND(FEE) AS Rounded_FEE


FROM Students;

Output
I & II
ROLLNO NAME DOB CITY STREAM FEE
1 Srinath 2015-11-05 Bangalore Science 2344.75
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89

ROLLNO NAME DOB CITY STREAM FEE


3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
1 Srinath 2015-11-05 Bangalore Science 2344.75
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89

iv. Total_Science_Fee
19838.53

v.. NAME CITY


Chandhan Delhi NCR
Giri Hyderabad

vi. NAME Last_Two_Characters


Srinath th
Supriya ya
Chandhan an
Giri ri
Kaveri ri
Vii
ROLLNO NAME DOB CITY STREAM Rounded_FEE
1 Srinath 2015-11-05 Bangalore Science 2345
2 Supriya 2016-09-25 Nagpur Humanities 5455
3 Chandhan 2018-12-18 Delhi NCR Arts 1235
4 Giri 2012-12-12 Hyderabad Science 8747
5 Kaveri 2015-02-18 Chennai Science 8747

6.aWrite python code to create the following DataFrame marks, and write python statements
to answer the question from (i) to (iii) 3M
(i) Display first two rows.
(ii) Display last two rows.
(iii) Add a new column called Total which is sum of all Tests.

6.b) Write program in python to create a bar chart that represents pass percentage of your
school from 2020 to 2024(including both the years) and also set the name to x-axis, y-axis
and title. Also save graph as simple.pdf. 5M
years=[2020,2021,2022,2023,2024]
pass=[95,94,900,95,98]
6.c) Consider the following table and write SQL commands for all the questions 7M
Table Name: STUDENT
ROLLNO NAME DOB CITY STREAM FEE
1 Srinath 2015-11-05 Bangalore Science 2344.75
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89

i. Create above table by applying primary key on Rollno column.


ii. Insert above data to the table.
iii. Display the details of all the students based on city.
iv. Display the number of students in each stream.
v. Display student names and city who born in November month.
vi. Display first two characters in every Student name.
vii. Delete the details of all the students who belongs to city Nagpur.

Answers
6a.
import pandas as pd

a = {'Test1': [45, 36, 78, 54],


'Test2': [58, 85, 96, 50],
'Test3': [47, 44, 88, 74],
'Test4': [65, 46, 77, 85]}
b = pd.DataFrame(a, index=['Ram', 'Peter', 'Alex', 'John'])
# (i) Display the first two rows
print(b.head(2))
# (ii) Display the last two rows
print(b.tail(2))
# (iii) Add a new column called Total which is the sum of all Tests
b['Total'] = b.sum(axis=1)
print(b)
Output

6a.
Test1 Test2 Test3 Test4
Ram 45 58 47 65
Peter 36 85 44 46

Test1 Test2 Test3 Test4


Alex 78 96 88 77
John 54 50 74 85

Test1 Test2 Test3 Test4 Total


Ram 45 58 47 65 215
Peter 36 85 44 46 211
Alex 78 96 88 77 339
John 54 50 74 85 263

6.b
import matplotlib.pyplot as plt

# Data
years = [2020, 2021, 2022, 2023, 2024]
pass_percentage = [95, 94, 900, 95, 98]

# Create a bar chart


plt.bar(years, pass_percentage, color='skyblue')

# Set x-axis and y-axis labels


plt.xlabel('Year')
plt.ylabel('Pass Percentage')

# Set the title


plt.title('School Pass Percentage from 2020 to 2024')

# Save the graph as a PDF file


plt.savefig('simple.pdf')

# Show the plot (optional)


plt.show()
6.c

Answers:
1. CREATE TABLE STUDENT ( ROLLNO INT PRIMARY KEY, NAME VARCHAR(30), DOB DATE, CITY
VARCHAR(30), STREAM VARCHAR(30), FEE DECIMAL(10,2)
2. INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (1, 'Srinath', '2015-11-05',
'Bangalore', 'Science', 2344.75);
INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES
(2, 'Supriya', '2016-09-25', 'Nagpur', 'Humanities', 5454.50);
INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (3, 'Chandhan', '2018-12-
18', 'Delhi NCR', 'Arts', 1234.56);
INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (4, 'Giri', '2012-12-12',
'Hyderabad', 'Science', 8746.89);
INSERT INTO STUDENT (ROLLNO, NAME, DOB, CITY, STREAM, FEE) VALUES (5, 'Kaveri', '2015-02-18',
'Chennai', 'Science', 8746.89);
3. SELECT * FROM STUDENT ORDER BY CITY;
4. SELECT STREAM, COUNT(*) AS NumberOfStudents FROM STUDENT GROUP BY STREAM;
5. SELECT NAME, CITY FROM STUDENT WHERE MONTH(DOB) = 11;
6. SELECT SUBSTRING(NAME, 1, 2) AS FirstTwoChars FROM STUDENT;
7. DELETE FROM STUDENT WHERE CITY = 'Nagpur';
SELECT * FROM STUDENT;

I. & II
ROLLNO NAME DOB CITY STREAM FEE
1 Srinath 2015-11-05 Bangalore Science 2344.75
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89
III.
ROLLNO NAME DOB CITY STREAM FEE
1 Srinath 2015-11-05 Bangalore Science 2344.75
5 Kaveri 2015-02-18 Chennai Science 8746.89
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
2 Supriya 2016-09-25 Nagpur Humanities 5454.50
IV.
STREAM NumberOfStudents
Science 3
Humanities 1
Arts 1
V.
NAME CITY
Srinath Bangalore
VI
FirstTwoChars
Sr
Su
Ch
Gi
Ka

VII.

ROLLNO NAME DOB CITY STREAM FEE


1 Srinath 2015-11-05 Bangalore Science 2344.75
3 Chandhan 2018-12-18 Delhi NCR Arts 1234.56
4 Giri 2012-12-12 Hyderabad Science 8746.89
5 Kaveri 2015-02-18 Chennai Science 8746.89

7a) Consider the following Series GradeXII and answer the questions.

3M
A 42
B 36
C 27
D 35

(i) Write python code to create above series Class using list
(ii) Write a statement to delete element whose index is ‘B’
(iii) Write a statement to add one element with 54 as value and index as ‘E’
5M

7b) Write a Python program using Matplotlib to create a bar chart representing the
following data. Set the x-axis label to "Categories", the y-axis label to "Values", and the
title to "Simple Bar Chart". Ensure that the bar colors are set to 'skyblue' and display the
chart.
7.c) 7M

i. Create Department table as per given data

primary key on Deptno column

ii. Insert data[10,CS,Riya],[20,AI,Shyam,],[30,ML,Ananya],[40,CN,Hari] into


Department table

iii. Display department name and their HOD name who are working in CS department
iv. Display deptname and their deptno whose HOD is Riya
v. Display deptno from Department table
vi. Display deptno whose HOD name starts with letter ‘A’
vii. Add one more column in the name of salary

import pandas as pd

# Creating the Series


grades = pd.Series([42, 36, 27, 35], index=['A', 'B', 'C', 'D'])
print(grades)

# Deleting the element with index 'B'


grades = grades.drop('B')
print(grades)

# Adding a new element with index 'E' and value 54


grades['E'] = 54
print(grades)
OUTPUT
A 42
B 36
C 27
D 35
dtype: int64
A 42
C 27
D 35
dtype: int64
A 42
C 27
D 35
E 54
dtype: int64

7b.
import matplotlib.pyplot as plt

# Data
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [10, 24, 36, 18]

# Create a bar chart


plt.bar(categories, values, color='skyblue')

# Set x-axis and y-axis labels


plt.xlabel('Categories')
plt.ylabel('Values')
# Set the title
plt.title('Simple Bar Chart')
# Show the plot
plt.show()

output:
7.c

1. CREATE TABLE Department ( Deptno INT PRIMARY KEY, Deptname VARCHAR(20), HODname VARCHAR(30)
);

2. INSERT INTO Department VALUES (10, 'CS', 'Riya');


INSERT INTO Department VALUES(20, 'AI', 'Shyam');
INSERT INTO Department VALUES (30, 'ML', 'Ananya');
INSERT INTO Department VALUES (40, 'CL', 'Hari');
3. SELECT Deptname, HODname FROM Department WHERE Deptname = 'CS';
4. SELECT Deptname, Deptno FROM Department WHERE HODname = 'Riya';
5. SELECT Deptno FROM Department;
6. SELECT Deptno FROM Department WHERE HODname LIKE 'A%';
7. ALTER TABLE Department ADD COLUMN salary DECIMAL(10,2);
Select * from Department;

Output
i.ii
Deptno Deptname HODname
10 CS Riya
20 AI Shyam
30 ML Ananya
40 CL Hari

iii.
Deptname HODname
CS Riya
iv.
Deptname Deptno
CS 10
v.
Deptno
10
20
30
40
vi.
Deptno
30

vii.
Deptno Deptname HODname salary
10 CS Riya NULL
20 AI Shyam NULL
30 ML Ananya NULL
40 CL Hari NULL

You might also like