0% found this document useful (0 votes)
19 views64 pages

Anki Tabish T

The document contains a comprehensive set of coding exercises and SQL queries related to data manipulation and visualization using Python and SQL. It includes tasks for creating and managing Series and DataFrames, performing arithmetic operations, and executing various SQL commands on multiple tables. Each section provides coding examples and expected outputs for tasks involving data analysis and database management.

Uploaded by

Ankita Bisht
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)
19 views64 pages

Anki Tabish T

The document contains a comprehensive set of coding exercises and SQL queries related to data manipulation and visualization using Python and SQL. It includes tasks for creating and managing Series and DataFrames, performing arithmetic operations, and executing various SQL commands on multiple tables. Each section provides coding examples and expected outputs for tasks involving data analysis and database management.

Uploaded by

Ankita Bisht
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/ 64

(2024-25)

NAME: ANKITA BISHT


CLASS: XII-C
ROLL NO: 26640670
SCHOOL: S.D.PUBLIC SCHOOL
INDEX

1. SERIES

2. DATA FRAME

3. DATA VISUALISATION

4. MY SQL

5. SINGLE TABLES

6. DOUBLE TABLES
Q1 Create a Series from a List

CODING:

OUTPUT:
Q2 Create a Series with Custom Index

CODING:

OUTPUT:
Q3 Arithmetic Operations on Series

CODING:

OUTPUT:
Q4 Accessing Elements in a Series

CODING:

OUTPUT:
Q5 Filtering a Series

CODING:

OUTPUT:
Q6 Series from a Dictionary

CODING:

OUTPUT:
Q7 Series Operations: Mean, Min, Max

CODING:

OUTPUT :
Q1 Create a DataFrame from a Dictionary

CODING:

OUTPUT:
Q2 Add a new column to DataFrame

CODING:

OUTPUT:
Q3 Delete a Column from Data Frame

CODING:

OUTPUT:
Q4 Select Rows based on Conditon
CODING:

OUTPUT:
Q5 Access Specific Row/Column using
loc and iloc

CODING:

OUTPUT:
Q6 Sort DataFrame by Column

CODING :

OUTPUT:
Q7 GroupBy and Aggregation

CODING :

OUTPUT :
Q8 DataFrame from List of Dictionaries

CODING :

OUTPUT:
Q9 Merge Two DataFrames

CODING:

OUTPUT:
Q10 Write a program that simulates weather
data and performs basic analysis on it, like
calcula�ng average temperature and total
rainfall.
CODING:

OUTPUT:
Q11. Creates a sales dataframe, and calculates
total sales and average sales per product.
CODING:

OUTPUT:
Q12. Analyzes a dataframe of COVID-19 cases in
different ci�es.

CODING:

OUTPUT:
Q13. Write a program to handles book data in
a library, analyzing the availability and
categoriza�on of books.

CODING:

OUTPUT:
Q14.Creates a dataframe of cricket players'
performances and calculates the total runs and
average strike rate.

CODING:

OUTPUT:
Q1 Line Plot
CODING :

OUTPUT :
Q2 Bar plot
CODING:

OUTPUT:
Q3 Histogram

CODING :

OUTPUT:
Q4 Pie chart
CODING:

OUTPUT:
Q5 Scatter Plot
CODING:

OUTPUT:
Q6 Box plot

CODING:

OUTPUT:
Q7 Multiple line plot
CODING:

OUTPUT:
Q8 . Stacked bar plot
CODING:

OUTPUT :
MY SQL
PROGRAMS
SINGLE TABLE
Q1.How to create database and use a
database.
Q2. Consider the table SPORTS given below. Write
commands in SQL for (i) to (iv) and output for (v) to (viii).
TABLE:Sports

(i) Display the names of the students who have grade 'A'
in either Game1 or Game2 or
both.
Ans: Select Name from SPORTS where Grade1-'A' OR
Grade2='A';
(ii) Display the number of students having game 'Cricket'.
Ans:Select count(*) from SPORTS Where Game1='Cricket'
OR Game2 'Cricket';
iii) Display the names of students who have same game
for both Gamel and Game2.
Ans:Select Name from SPORTS where Game1-Game2;
(iv) Display the games taken by the students whose name
starts with 'A'.
Ans: Select Game1, Game2 from SPORTS where Name
LIKE 'A%';
(v) SELECT COUNT(*) FROM SPORTS.
Ans: 6
(vi) SELECT DISTINCT Class FROM SPORTS.
Ans :7
9
10
(vii) SELECT MAX(Class) FROM STUDENT;
Ans: 10
(vii) SELECT COUNT(*) FROM SPORTS GROUP BY Game1;
Ans: 2
2
1
1
Q3.Consider the following tables HOSPITAL. Give outputs
for SQL queries (i) to (iv) and write SQL commands for
the statements (v) to (viii)
TABLE-Hospital

(i) Select SUM(Charge) from HOSPITAL where Sex='F';


Ans: 1200
(ii) Select COUNT (DISTINCT Department) from HOSPITAL;
Ans: 4
(iii) Select SUM(Charge) from HOSPITAL group by
Department;
Ans: 1050
700
1150
1320
(iv) Select Name from HOSPITAL where Sex='F' AND Age >
20;
Ans : Dhanya
(v) To show all informa�on about the pa�ents whose
names are having four characters only.
Ans:SELECT * FROM HOSPITAL WHERE NAME LIKE "":
(vi) To reduce Rs 200 from the charge of female pa�ents
who are in Cardiology department.
Ans: UPDATE HOSPITAL SET CHARGE CHARGE-200 WHERE
(DEPARTMENT = 'CARDIOLOGY' AND SEX = 'F');
(vii) To insert a new row in the above table with the
following data: 11, 'Rakesh', 45, 'ΕΝΤ', (08/08/08), 1200,
'M'
Ans : INSERT INTO HOSPITAL
VALUES(11, 'Rakesh', 45, 'ENT', {08/08/08), 1200, 'M');
(viii) To remove the rows from the above table where age
of the pa�ent > 60.
Ans : DELETE FROM HOSPITAL WHERE AGE > 60;
Q4. Consider the following table named TEACHER and
answer the following ques�ons based on it.

2.Insert record
3.selec�ng all teachers

4.Finding Teachers in a Specific Department

5.Upda�ng a teacher's salary

6.Dele�ng a teacher record


7.Calcula�ng average salary

8.Coun�ng teachers by gender


Q5 . Consider the table SCHOOL (2) given below. Write
commands in SQL for (1) to (4) and output for (5) to
(8).
TABLE-SCHOOL

To display all informa�on about teachers of PGT


category.
Ans: SELECT * FROM School WHERE ry=^ prime PG * T'
;
ii. To list the names of female teachers of Hindi
department.
Ans: SELECT name FROM School WHERE Gender = 'F'
AND Department = 'Hindi';
iii. To list names, departments and date of hiring of all
the teachers in ascending order of date of joining
Ans: SELECT name, department, hiredate FROM
School ORDER BY hiredate;
iv. To count the number of teachers in English
department.
Ans:SELECT count(*) FROM School WHERE
department = 'English';
v. SELECT MAX(Hiredate) FROM School;
Ans: 9/2/1994
vi. SELECT DISTINCT (category) FROM School;
Ans :TGT
PRT
PGT
vii. SELECT COUNT(*) FROM SCHOOL WHERE Category
= "PGT"
Ans: 1
viii. SELECT AVG(Salary) FROM SCHOOL group by
Gender;
Ans :24500
24000
Q6.Consider the following tables PRODUCT and
answer (b) and (c) part of this ques�on
TABLE - Product

i. To show details of all the PC with stock more


than 110.
Ans: SELECT * FROM PRODUCT
WHERE PNAME = 'PC' AND STOCK > 110;
ii. To list the company which gives warranty for
more than 2 years.
Ans: SELECT COMPANY FROM PRODUCT
WHERE WARRANTY > 2;
iii. To find stock value of the BPL Company
where stock value is sum of the products of
price and stock.
2
Ans: SELECT PRICE STOCK "STOCK VALUE FROM
PRODUCT WHERE COMPANY 'BPL';
iv. To show number of products from each
company.
Ans: SELECT COMPANY, COUNT(DISTINCT
PNAME) "PRODUCTS" FROM PRODUCT GROUP
BY COMPANY:
v. To count the number of PRODUCTS which are
manufactured in 2009.
Ans: SELECT COUNT(*) FROM PRODUCT WHERE
YEAR (MANUFACTURE) = 2009;
vi. To show the PRODUCT name which are
within warranty as on date.
Ans:SELECT PNAME FROM PRODUCT WHERE
YEAR (MANUFACTURE + CURDATE())
<WARRANTY;
vii. Select COUNT (dis�nct company) from
PRODUCT;
2
Ans: 4
4
viii. Select MAX (price) from PRODUCT where
WARRANTY<=3;
Ans: 39000
ix. select AVG (price) from PRODUCT where
Company="SONY";
Ans: 15000
Χ. Select MIN (price) from PRODUCT where
stock<200;
Ans: 1200
Q7.Consider the following tables BOOKS. Write
SQL commands for the statements (i) to (iv) and
give outputs for SQL queries (v) to (viii).

1). To list the names from books of Text type.


Ans: SELECT Book_Name FROM BOOKS WHERE
Type = 'Text':
ii). To display the names and price from books
in ascending order of their price.
Ans: SELECT Book_Name, Price FROM BOOKS
ORDER BY Price;
iii). To increase the price of all books of EPB
publishers by 50.
Ans: UPDATE BOOKS SET Price = Price + 50
WHERE Publisher = 'EPB';
iv). To display the Book_Name, Quan�ty and
Price for all C++ books.
Ans: SELECT Book_Name, Quan�ty, Price FROM
BOOKS WHERE Book_Name LIKE '%C++%';
v). Select max(price) from books;
Ans: 750
vi). Select count(DISTINCT Publishers) from
books where Price >=400;
Ans: 2
vii). Select Book_Name, Author_Name from
books where Publishers = 'First':
Ans: The Tears William Hopkins
Thuderbolts Anna Roberts
viii). Select min (Price) from books where type =
'Text':
Ans: 350
Q1.Consider the following tables. Write SQL
command for the statements (i)to(iv)and give
outputs for the SQL quries (v) to (vii).
TABLE:SENDER

TABLE:RECIPIENT

i) To display the names of all senders from


Mumbai.
Ans: Select from Sender where SenderCity
Mumbai';
(ii) To display the recID, senderName,
senderAddress, RecName, RecAddress for every
recipt.
Ans: Select recID, SenderName, SenderAddress,
RecName. RecAddress from Sender, Recipient
where Sender Senderid Recipient.Renderld:
(iii) To display the sender details in ascending
order of SenderName.
Ans: Select from Sender order by SenderName;
(iv) To display number of Recipients from each
city.
Ans: Select RecCity, Count(*) from Recipient
group by RecCity:
CnorName
R Singhal
Amit Kumar
CneeName
Rahul Kishore
S mital
CneeName CneeAddress
P Dhingra 16/j,Moore Enclave
B P jain 13,Block , d,a, viha
(v) SELECT A.SenderName A, B.RecName FROM
Sender A, Recipien! B WHERE A.SenderID=B.
SenderID AND B.RecCity-Mumbai';
Ans: SenderName RecName
R.JaiN H.Singh
S.Jha P.K.Swamy
(vi) SELECT RecName, RecAddress
FROMRecipient WHERE RecCity Not IN
('Mumbai', Kolkata');
Ans: RecName RecAddressS
Mahajan 116, A Vihar
S Tripa� 13, B1 D, Mayur Vihar
(vii) SELECT RecID, RecName FROM Recipient
WHERE SenderID = 'MU02' OR SenderID =
'ND50';
Ans: RecID RecName
ND08 S MahajaN
ND48 STripathi
Q2.Consider the following tables Item and
Customer. Write SQL commands for the statement
(i) to (iv) and give outputs for SQL queries (v) to (viii)
Table: ITEM

TABLE:CUSTOMER
(i) To display the details of those Customers
whose city is Delhi.
Ans: Select all from Customer Where
City="Delhi"
(ii) To display the details of Item whose Price is
in the range of 35000 to 55000 (Both values
included).
Ans: Select all from Item Where Price>=35000
and Price <=55000
(iii) To display the CustomerName, City from
table Customer, and ItemName and Price from
table Item, with their corresponding matching
I_ID.
Ans: Select CustomerName, City, ItemName,
Price from Item, Customer where
Item.I_ID=Customer.I_ID.
(iv) To increase the Price of all Items by 1000 in
the table Item.
Ans: Update Item set Price-Price+1000
(v) SELECT DISTINCT City FROM Customer.
Ans: City
Delhi
Mumbai
Bangalore
(vi) SELECT ItemName, MAX(Price), Count(*)
FROM Item GROUP BY ItemName;
Ans:
ItemName Max(Price) Count(*)
Personal Computer 37000 3
Laptop 57000 2
(vii) SELECT CustomerName, Manufacturer
FROM Item, Customer WHERE
Item.Item_Id=Customer.Item_Id;
Ans:

CustomerName Manufacturer Name


N.Roy PQR
H.Singh XYZ
R.Pandey COMP
C.Sharma PQR
K.Agarwal ABC
(viii) SELECT ItemName, Price * 100 FROM Item
WHERE Manufacturer = 'ABC';
Ans:
ItemName Price*100
Personal Computer 3500000
Laptop 5500000
Q3. Study the following tables FLIGHTS and FARES
and write SQL commands for the ques�ons (i) to
(iv).
TABLE: FLIGHTS

TABLE:FARES
(i) Display FL_NO and NO_FLIGHTS from "KANPUR"
TO "BANGALORE" from the table FLIGHTS.
Ans: Select FL_NO, NO_FLIGHTS from FLIGHTS
where Star�ng-"KANPUR" AND ENDING
"BANGALORE"
(ii) Display the FL_NO and fare to be paid for the
flights from DELHI to MUMBAI using the tables
FLIGHTS and FARES, where the fare to paid
FARE+FARE+TAX%/100.
Ans: Select FL_NO, FARE+FARE+(TAX%/100) from
FLIGHTS, FARES where Star�ng-"DELHI" AND
Ending-"MUMBAI"
(iii) Display the minimum fare "Indian Airlines" is
offering from the tables FARES.
Ans: Select min(FARE) from FARES Where AIRLINES-
"Indian Airlines";
(iv) Select FL_NO,NO_FLIGHTS, AIRLINES from
FLIGHTS, FARES Where STARTING = "DELHI" AND
FLIGHTS.FL_NO = FARES.FL_NO
Ans: FL_NO NO_FLIGHTS AIRLINES IC799 2 Indian
Airlines
Q4.Consider the following tables Product and
Client. Write SQL commands for the statement (i)
to (iv) and give outputs for SQL queries (v) to (viii)
Table: PRODUCT

TABLE: CLIENT
(i) To display the details of those Clients whose
city is Delhi.
Ans: Select all from Client where City="Delhi"
(ii) To display the details of Products whose Price
is in the range of 50 to 100 (Both values
included).
Ans: Select all from product where Price between
50 and 100
(iii) To display the ClientName, City from table
Client, and ProductName and Price from table
Product, with their corresponding matching P_ID.
Ans: Select ClientName, City, ProductName, Price
from Product, Client where
Product.P_ID=Client.P_ID.
(iv) To increase the Price of all Products by 10
Ans: Update Product Set Price Price +10
(v) SELECT DISTINCT Address FROM Client.
Ans: (The above ques�on may consist DISTINCT
City. If it is DISTINCT City, the following is the
answer)
City
----------
Delhi
Mumbai
Bangalore
vi) SELECT Manufacturer, MAX(Price), Min(Price),
Count(*) FROM Product GROUP BY Manufacturer;
Ans:
Manufacturer Max(price) Min(price)
Count(*)
LAK 40 40 1
ABC 55 45 2
XYZ 120 95 2
(vii) SELECT ClientName, ManufacturerName
FROM Product, Client WHERE
Client.Prod_Id=Product.P_Id;
Ans:
ClientName ManufacturerName
Cosme�c Shop ABC
Total Health ABC
Live Life XYZ
Prety Woman XYZ
Dreams LAK
(viii) SELECT ProductName, Price * 4 FROM
Product.
Ans. ProductName Price*4
Talcom Poweder 160
Face Wash 180
Bath Soap 220
Shampoo 480
Face Wash 380

Q5.Consider the following tables Consignor and


Consignee. Write SQL command for the
statements (i)to(iv) And give outputs for the
SQL quries (v) to (viii).
TABLE: CONSIGNOR
TABLE:CONSIGNEE

(i) To display the names of all consignors from


Mumbai.
Ans: Select CnorName from Consignor where
city="Mumbai";
(ii) To display the cneeID, cnorName,
cnorAddress, CneeName, CneeAddress forevery
Consignee.
Ans: Select Cneeld, CnorName, CnorAddress,
CneeName, CneeAddress from Consignor,
Consignee where
Consignor.CnorId=Consignee.Cnorld;
(iii) To display the consignee details in
ascending order of CneeName.
Ans: Select * from Consignee Orderby
CneeName Asc;
(iv) To display number of consignors from each
city.
Ans: Select city, count(*) from Consignors group
by city;
(v) SELECT DISTINCT City FROM CONSIGNEE;
Ans:
CneeCity
Mumbai
New Delhi
Kolkata
(vi) SELECT CneeID, CneeName FROM
Consignee WHERE CnorID = 'MU15' OR CnorID
= 'ND01';
Sendercity
New Delhi
Mumbai
Ans: CneelD
CneeName
MU05
Rahul Kishore
KO19 A P Roy

You might also like