0% found this document useful (0 votes)
2K views12 pages

Practical Practice Question File Solutions-Friends

Uploaded by

Ann Roby
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)
2K views12 pages

Practical Practice Question File Solutions-Friends

Uploaded by

Ann Roby
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/ 12

PR1

PYTHON
a) Write the code to create the series ‘serObj’ and answer the questions followed.
Jan 31
Feb 28
Mar 31
Apr 30
i) Write the command to add one row: ‘May’ – 31
ii) Write the command to update Feb to 29
iii) Write the command to change the index to 1, 2, 3, 4, 5 in place of Jan, Feb, Mar, Apr,
and May.
iv) Write a command to print a month name having number of days less than 31.
v) Write the output:
(a) print(serObj < 30)
(b) print(serObj + 3)
1)a)import pandas as pd
serObj=pd.Series([31,28,31,30], index=['Jan','Feb','Mar','Apr'])
i)serObj['May']=31
ii)serObj['Feb']=29
iii)serObj.index=[1,2,3,4,5]
iv)serObj.index=['Jan','Feb','Mar','Apr','May']
serObj[serObj<31]
v)a)print(serObj < 30)
b)print(serObj+3)
print(serObj)

b) Write a Python program to display a BAR CHART of the number of students in a


school.
(i) Use different colors for each bar.
(ii) Title for x axis should be ‘Groups’ and title for y axis should be ‘Number of
Students’.
(iii) Ensure the title of chart is “Group wise Students” and grid line must be shown.
Sample data: Group: I, II, III, IV and Strength: 38, 30, 45, 49
B)i)import matplotlib.pyplot as plt
Classes=['I','II','III','IV']
Students=[38,30,45,49]
plt.bar(Classes,Students,color=['red','green','blue','black'])
plt.xlabel('Classes')
plt.ylabel('No of students')
plt.title('Class wise students')
plt.show()
Q2. SQL Queries:

a) Create a table DRUGDB with the fields given in the table below and assume the data
type of your own.
b) Consider the table DRUGDB. Write the SQL commands for queries given below:
(i) To increase the price of “Paracetamol” by 35.
(ii) To display the drugid, Rxid and pharmacy name of all records in descending order of
their price.
(iii) Display all the details of the drugs where name starts with ‘C’ and has ‘sh’
somewhere in the name.
(iv) Display the drug name in lower case along with price rounded off to the nearest
integer.
(v) Delete the field name loc from drugdb table.
2)a) create table DRUGDB(RxID varchar(5) primary key,DrugID int(4),drugname varchar(30),
price decimal(10,2),PharmacyName varchar(30),loc varchar(30));
insert into DRUGDB values('R1000',5476,'AMPLODIPINE',100.00,'RxPHARMACY','BEAS');
insert into DRUGDB values('R1001',2345,'PARACETAMOL',10.75,'RAJPHARMACY','UNA');
insert into DRUGDB values('R1002',1236,'NEBISTAR',60.50,'MYCHEMIST','SOLAN');
insert into DRUGDB values('R1003',6512,'VITAPLUS',150.50,'MYCHEMIST','GURGAON');
insert into DRUGDB values('R1004',5631,'COVISHIELD',1050.50,'OXFORD','PUNE');

b)i) update DRUGDB set price=price+35 where drugname='PARACETAMOL';

ii) select DrugID, RxID,PharmacyName from DRUGDB order by price desc;


iii) select * from DRUGDB where drugname like'C%SH%';

iv)select lower(drugname),round(price,0) from DRUGDB;

v)alter table DRUGDB drop loc;

PR2
PANDAS & MATPLOTLIB
a) Write the code to create a DataFrame ‘df’ and answer the questions:

i) Write a command to add one row ‘Chris’ with values 75.6, 98.6, 56.0
ii) Write a command to add one column Total = Maths + Science + SST
iii) Write a command to print only the Score of Maths and Science.
iv) Write a command to update the marks of Science of Sudha to 85.0
v) Write a command to delete a row - Mohan.
a)import pandas as pd
data={'Maths':{'Amit':100,'Mohan':95,'Sudha':85},'Science':{'Amit':100,'Mohan':50,'Sudha':90},'S
ST':{'Amit':60,'Mohan':57.48,'Sudha':53.58}}
df=pd.DataFrame(data)
print(df)

i)df.loc[‘Chris’]=[75.6,98.6,56.6]
ii)df[‘Total’]=df[‘Maths’]+df[‘Science’]+df[‘SST’]

III)df[[‘Maths’,’Science’]]

iv)df.at[‘Sudha’,’Science’]=85.0

OR
df.iat[2,1]=85.0

v)df=df.drop[‘Mohan’]

b) Write a Python program to display the given Result using a BAR CHART

(i) Set the title of graph is “Result Analysis”.


(ii) Display the legends.
(iii) Display the label of x axis to “Name” and y axis to “Score”
import matplotlib.pyplot as plt
import numpy as np
Names = ['Amit', 'Mohan', 'Science']
x=np.arange(len(Names))
Maths = [100, 95, 85]
Science = [100, 50, 90]
SST = [60, 57.48, 53.48]
plt.bar(x, Maths, color='red', width=1.5, label='Mat')
plt.bar(x+.25, Science, color='blue', width=1.5, label='Sci')
plt.bar(x+.50, SST, color='green', width=1.5, label='SST')
plt.title('Result Analysis', fontsize=15)
plt.xlabel('Names', fontsize=15)
plt.ylabel('Score', fontsize=15)
plt.legend()
plt.show()
Q2 SQL Queries:

Write the commands in SQL for (i) to (vi):


(i) To list the names of items and their unit price that have unit prices of less than 800
and discounts of more than 5%.
(ii) To display the number of items that have more than 10% as a discount.
(iii) To display item code and unit price in decreasing order of unit price.
(iv) To increase the unit price of each item by 10% of their unit price.
(v) To display the highest unit price of items.
(vi) To display the names of items with ‘Baby’ anywhere in their item names.
Find output for (vii) and (viii):
(vii) SELECT MID (Item,1,2) FROM Infant;
(viii) SELECT AVG(UnitPrice) FROM Infant WHERE DATEPURCHASE > '2015-01-01';
i) SELECT Item, UnitPrice FROM Infant WHERE UnitPrice < 800 AND Discount > 5;

ii)Select count (*) from Infant where Discount>10;

iii)Select ItemCode, UnitPrice from Infant order by UnitPrice desc;

iv)Update Infant set UnitPrice=Unitprice+UnitPrice*10/100;


v)select max(UnitPrice) from Infant;

vi)Select Item from Infant where like ‘%Baby%;

vii)

viii)

PR3
PANDAS & MATPLOTLIB
a) Write the code to create a DataFrame ‘RESULT’ and answer the questions:

i) Write a command to add one row T5 with values 75.6, 98.6, 56.0, 92.5
ii) Write a command to add one column Total = col1+col2+col3
iii) Write a command to change the column names Col1 to Maths, Col2 to Science, Col3
to SST.
iv) Write a command to print Score of Maths and Science only.
v) Write a command to update a value of T3 Row and Col1 / update NaN to 85.0
a)import pandas as pd
import numpy as np
data = {'Col1': [100.0, 95.8, np.nan, 82.0],
'Col2': [100.0, 100.0, 100.0, 85.0],
'Col3': [60.0, 57.48, 53.48, np.nan]}
index = ['T1', 'T2', 'T3', 'T4']
RESULT = pd.DataFrame(data, index)
print(RESULT)
i)RESULT.loc['T5'] = [75.6, 98.6, 56.0]

ii)RESULT['Total'] = RESULT['Col1'] + RESULT['Col2'] + RESULT['Col3']

iii)RESULT = RESULT.rename(columns={'Col1': 'Maths', 'Col2': 'Science', 'Col3': 'SST'})

iv)print(RESULT[['Maths', 'Science']])

v)RESULT.at['T3', 'Maths'] = 85.0

b) Write a Python program to display the given below data using a LINE PLOT:

(i) Set the title of the graph as “Result Analysis”.


(ii) Display the legends.
(iii) Display the label of x axis as “Name” and y axis as “Score”.

import matplotlib.pyplot as plt


Names = ['Amit', 'Mohan', 'Science']
Maths = [100, 95, 85]
Science = [100, 50, 90]
SST = [60, 57.48, 53.48]
plt.plot(Names, Maths, color='red', ls='dashdot', marker='*', linewidth=1.5, label='Mat')
plt.plot(Names, Science, color='blue', ls='dashdot', marker='o', linewidth=1.5, label='Sci')
plt.plot(Names, SST, color='green', ls='dashdot', marker='D', linewidth=1.5, label='SST')
plt.title('Result Analysis', fontsize=15)
plt.xlabel('Names', fontsize=15)
plt.ylabel('Score', fontsize=15)
plt.legend()
plt.show()

2)SQL Queries:-
Consider the following tables CARDEN. Write SQL commands for the following
statements.
create table CARDEN(Ccode int(3) primary key, CarName varchar(10), Company varchar(10),
Color varchar(10), Capacity int(1), Charges int(2));
insert into CARDEN values(501,'A-Star','Suzuki','Red',3,14);
insert into CARDEN values(503,'Indigo','Tata','Silver',3,12);
insert into CARDEN values(502,'Innova','Toyota','White',7,15)
;insert into CARDEN values(509,'SX4','Suzuki','Silver',4,14)
;insert into CARDEN values(510,'C Class','Mercedes','Red',4,35);
select * from CARDEN;

a) To display the names of all Silver colored Cars.


b) To display the name of the car, Company, and capacity of Cars in descending order of
their seating capacity
c) To display the highest charges at which a vehicle can be hired from Carden.
d) To increase the charges by 5% for Suzuki company
e) Write a SQL query to display CarName and Company together of those cars whose
name have 'n' anywhere or charges greater than 14
f) Write output for the following MYSQL queries:-
(i) SELECT LEFT(CarName, 3) FROM CARDEN;
(ii) SELECT MID(CarName, 2,3) FROM CARDEN;
(iii) SELECT POW(CAPACITY, 2) FROM CARDEN WHERE CHARGES IN (12,14);
(iv) SELECT MAX(CHARGES), COMPANY FROM CARDEN GROUP BY COMPANY;
a)Select CarName from CARDEN where Color=’Silver’;
b)Select CarName, Company, Capacity from CARDEN where Capacity desc;

c)Select max(Charges) from CARDEN;

d)Update CARDEN set Charges=Charges*5/100 where CarName=’Suzuki’;

e)Select CarName, Company from CARDEN where CarName like’%n%’ and Charges>14;

f)i)

ii)

iii)

iv)

PR4
PANDAS & MATPLOTLIB
1)A)Consider the following DataFrame df and answer the given questions (i) - (v):
import pandas as pd
index = ['Air India', 'Kuwait Airways', 'Jet Airways', 'Indigo']
data = {'Year': ['2018', '2019', '2020', '2021'], 'Month': ['Jan', 'Feb', 'Mar', 'April'], 'Passenger':
[25, 30, 45, 67]}
Airways = pd.DataFrame(data, index=index)
print(Airways)

i. Write the command in python to extract data from ‘Air india’ to ‘Indigo’ for all
columns.
ii. Write the command in python to extract the details of ‘Indigo’ flight.
iii. Write the command in python to extract the number of passengers in all flights.
iv. Write the command in python to extract all the details for all flights.
v. Write the command in python to extract data of Kuwait Airways, no. of passengers
using ‘at’.
i)Airways.loc['Air India':'Indigo','Year':'Passenger']

ii)Airways.loc[‘Indigo’]
iii)Airways.loc[[:,’Passenger’]
iv)Airways.loc[[:,’Year’:’Passenger’]
v)Airways.at[‘Kuwait Airways’,’Passenger’]
OR
Airways.[[‘Year’,’Passenger’]][Airways[‘Month’]==’Jan’]

B. Draw the following Line graph representing the percentage of marks for each person.

(i) Set the appropriate label to the x-axis and y-axis.


(ii) Set the title of Graph “Percentage Comparison”
import matplotlib.pyplot as plt
x = ['Anu','Hari','Riya']
y=[40,50,45]
plt.plot(x,y, linewidth='5', ls='dashdot',color='r')
plt.title('Percentage Comparison')
plt.xlabel('Marks')
plt.ylabel('Names')
plt.savefig('percentagecomparison_trial')
plt.show()

Q2. SQL Queries:- Write the SQL Commands to perform the following:-
i. Create a Hospital table with the P id, name, age, department, charges and gender as
attributes where PID is the primary key.(Insert 5 rows)
ii. Insert the details of a new patient in the above table. (6th row)
iii. Delete the details of a patient whose age is greater than 60 in the above table.
iv. Use the select command to get the details of the patients with charges more than
250.
v. Find the min, max, sum, and average of the charges in the Hospital table.
vi. Find the total number of patients in each department in the HOSPITAL.
vii. To arrange the patients in descending order of Gender.
i)create table Hospital(Pid int(5) primary key, name varchar(30), age int(5), department
varchar(30), charges int(5), gender varchar(1));
insert into Hospital values(‘P1001’, ‘ELISE’,24,’CARDIOLOGY’,250, ‘F’);
insert into Hospital values(‘P1002’, ‘ADAM’,39,’PSYCHOLOGY’,129, ‘M’);
insert into Hospital values(‘P1003’, ‘FRANCESCA’,20,’ONCOLOGY’,270, ‘F’);
insert into Hospital values(‘P1004’, ‘EMILY’,57,’NEUROLOGY’,158, ‘F’);
insert into Hospital values(‘P1005’,‘BRANDON’,36,’PHYSIOLOGY’,290, ‘M’);

ii)insert into Hospital values(‘P1006’, ‘DOM’,28,’ACCOUNTANT’,300, ‘M’);

iii)delete from Hospital where age > 60;


iv)Select * from Hospital where charges>250;

v)Select min(charges), max(charges),sum(charges), avg(charges) from Hospital;

vi)select department, count(*) as name from Hospital group by department;

vii)select name from Hospital order by gender desc;

You might also like