Practical Practice Question File Solutions-Friends
Practical Practice Question File Solutions-Friends
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)
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');
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
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]
iv)print(RESULT[['Maths', 'Science']])
b) Write a Python program to display the given below data using a LINE PLOT:
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;
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.
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’);