0% found this document useful (0 votes)
43 views5 pages

Pyhtonpractice Questions

The document contains 6 sets of SQL queries and Python code related to dataframes. Each set contains questions related to creating databases and tables, performing CRUD operations, aggregation, plotting and more. A variety of data like customer, product, employee is used across the questions.

Uploaded by

afrahsabeer
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)
43 views5 pages

Pyhtonpractice Questions

The document contains 6 sets of SQL queries and Python code related to dataframes. Each set contains questions related to creating databases and tables, performing CRUD operations, aggregation, plotting and more. A variety of data like customer, product, employee is used across the questions.

Uploaded by

afrahsabeer
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/ 5

SET:1

Q1: i.
import pandas as pd
item=pd.DataFrame({"Itemname":["Cream","Soap","Shampoo","Conditioner"] ,
"Price" : [80,15,50,45],
"Expirydate" : ["2024-05-12","2025-10-24",
"2026-02-10","2024-07-21"]} ,
index = ["W","X","Y","Z"])
print(item)
ii.
item.Price['Y']=90
print(item)
iii.
print(item[['Itemname','Price']])
iv.
item['Discount']= item.Price*4/100
print(item)
v.
import matplotlib.pyplot as plt
item.plot.bar("Itemname","Price")
plt.xlabel("item")
plt.ylabel("price")
plt.show()
Q2: i. create table vehicle(Vcode int primary key, Model varchar(15),Type
varchar(12), Rentaldate date, Charges int, Customer varchar(20));
insert into vehicle values(10, “Suzuki”, “ SUV” , “2023-12-23”, 150, “Company”);
insert into vehicle values(25, “Dodge”, “Sedan”, “2024-01-20”, 250 , “Individual”);
insert into vehicle values(53 , “Audi”, “Sports” , “2024-01-10”, 300 , “Individual”);
insert into vehicle values(14,”Chrysler “, “4WD”, “2023-11-21”, 275 , “Company”);
insert into vehicle values(41,“Peugeot”,“Hatchback”,“2023-12-29”,290, “Company”);
select * from vehicle;
ii. select model, monthname(Rentaldate) from vehicle;
iii. select Customer, sum(charges) from vehicle group by Customer;
iv. update vehicle set charges = charges + charges *(8/100) where Customer =
"Company";
Select * from vehicle;
SET 2
Q1: i.
import pandas as pd
country=pd.DataFrame({"Country" : ["India","United States","Indonesia","Brazil"] ,
"Companies" : [43,32,26,20],
"Surveydate" : ["2023-05-11","2023-09-02",
"2023-06-07","2023-07-15"]} ,
index = ["A","B","C","D"])
print(country)
ii.
print(country.loc[["A","D"]])
iii.
country.loc['E']=["Thailand", 43, "2023-05-21"]
print(country)
iv.
country=country.drop("Surveydate",axis=1)
print(country)
v.
import matplotlib.pyplot as plt
country.plot.line("Country","Companies")
plt.title(‘Country-wise companies’)
plt.xlabel("Countries")
plt.ylabel("Companies")
plt.show()
Q2:
i. create table SCHOOL(TID INT primary key, TName varchar(15),Post
varchar(3),Subject varchar(12),Salary int,Dt_join date);
INSERT INTO SCHOOL VALUES(11,"Ms.Soha","PGT","IP",76000,"2018-01-07");
INSERT INTO SCHOOL VALUES(12,"Mr.Joy","TGT","Science",45000,"2018-04-
01");
INSERT INTO SCHOOL VALUES(13,"Ms. Peace"," PRT","English",35000,"2018-
08-11");
INSERT INTO SCHOOL VALUES(14,"Ms. Naala","PGT","IP",80000,"2018-01-21");
INSERT INTO SCHOOL VALUES(15,"Mr. Jenson","TGT","Hindi",43000,"2018-04-
07");
select * from SCHOOL;
ii. select post, AVG(Salary) from School group by post;
iii. select Tname, Salary from school where monthname(DT_JOIN)="January";
iv. update SCHOOL set Salary=Salary+ Salary*10/100 where Subject="IP";
select *from SCHOOL;
SET 3
Q1: i.
import pandas as pd
company = pd.DataFrame({"Ename" : ["Pearl","Jay","Lana"] ,
"Post" : ["Analyst","Administrator","Programmer"],
"Salary" : [45000,43000,40000],
"Dt_join" : ["2018-04-01","2022-08-11","2017-05-19"]},
index = [101,102,103])
print(company)
ii.
print(company[["Ename","Post"]])
iii.
company.loc[104]=["Saaya", "Engineer",55000, "2023-06-21"]
print(company)
iv.
company = company.rename({"Post":"Designation"} , axis = 1)
print(company)
v.
import matplotlib.pyplot as plt
company.plot.bar("Ename","Salary")
plt.title("Salary Chart")
plt.xlabel("Emplyees")
plt.ylabel("Salary")
plt.show()
Q2:
i. Create table music(artist varchar(15) primary key, songtitle varchar(15),
Views_millions int, genre varchar(10), dt_release date);
insert into Music values("May", "Sea”,16,"Reggae"," 2020-04-01");
insert into Music values("Sean"," Sky",13,"Jazz"," 2022-06-05");
insert into Music values("Win", "Earth",16,"Blues"," 2021-08-11");
insert into Music values("Pearl","Fairy",15,"Jazz"," 2021-01-07");
insert into Music values("Rain"," Bird", 14,"Reggae","2021-04-12");
insert into Music values("Gem","Wind ", 15,"Hip Hop","2021-01-07");
select * from Music;
ii. select count(*) from Music where year(dt_release)=2021;
iii. select genre, sum( Views_millions) from Music group by genre;
iv. SELECT artist, songtitle FROM Music ORDER BY Artist DESC;
SET 4
Q1:
i.
import pandas as pd
hospital = pd.DataFrame({"Dname" : ["Vini","Amar","Jeena","Sam"] ,
"Fees" : [300,250,200,125],
"Join_date" : ["2018-04-01","2022-08-11",
"2021-05-19","2023-01-05"]},
index = ["D1","D2","D3","D4"])
print(hospital)
ii.
print(hospital[["D2","D4"]])
iii.
hospital["Days"]=["Tuesday", "Friday", "Thursday", "Monday"]
print(hospital)
iv.
hospital.Fees["D4"]=200
print(hospital)
v.
import matplotlib.pyplot as plt
hospital.plot.line("Dname","Fees")
plt.title("Doctor-wise Fees")
plt.xlabel("Doctors")
plt.ylabel("Fees")
plt.show()
Q2:
i. create table Apparel (Gcode varchar(4) primary key,Garment varchar(15),Price
int, Displayed date, Designer varchar(15));
insert into Apparel values("A025","Formal shirt",500,"2023-12-07","Tommy
Hilfiger");
insert into Apparel values("A100","Skirt", 450,"2024-01-12","Ganni");
insert into Apparel values("A093","Jeans",300,"2023-11-26","Van Heusen");
insert into Apparel values("A076","Trousers",475,"2023-10-13","Van Heusen");
insert into Apparel values("A057","Jacket",600,"2024-01-29","Tommy Hilfiger");
insert into Apparel values("A081","Coat",650,"2024-01-31","Ganni");
Select * from Apparel;
ii. select Designer, avg(Price) from Apparel group by Designer;
iii. update Apparel set Price=Price - Price*6/100 where Designer= "Ganni";
select * from Apparel;
iv. select Garment, Dayname(Displayed) from Apparel;
SET 5
Q1:
i.
import pandas as pd
Lawfirm = pd.DataFrame({"Lawyer" : ["Jared","Dean","Tia"] ,
"Type" : ["Criminal ","Corporate ","Immigration "],
"Fees" : [20000,25000,18000],
"Start_date" : ["2015-08-16","2014-12-30","2016-03-29"]} ,
index = [25,26,27])
print(Lawfirm)
ii.
print(Lawfirm[["Lawyer","Fees"]])
iii.
Lawfirm['Bonus']= Lawfirm.Fees*12/100
print(Lawfirm)
iv.
Lawfirm =Lawfirm.drop(26,axis=0)
print(Lawfirm)
v.
import matplotlib.pyplot as plt
Lawfirm.plot.bar("Lawyer","Fees")
plt.title("Lawfirm Details")
plt.xlabel("Lawyers")
plt.ylabel("Fees")
plt.show()
Q2:
i. Create table GYM(Member varchar(2) primary key,Trainer varchar(10), Days
varchar(3), Workout varchar(20),Joined date):
Insert into GYM values(“M1“,“ Reya“, “MTS “ , “Pilates “, “2020-04-01“);
Insert into GYM values(“M2“,“Star“,“ SSF“,“Circuit“,“2022-09-10“);
Insert into GYM values(“M3“,“Reya“,“TT“,“HIIT“,“2021-08-11“);
Insert into GYM values(“M4“,“Reya“,“MTS“,“Aerobics“,“2021-01-07“);
Insert into GYM values(“M5“,“Star“,“WFS“,“Romanian deadlift “,“2021-03-16“);
Insert into GYM values(“M6 “ ,“sky“,“MTW“,“Bench press“,“2021-01-04“);
Select * from GYM;
ii. select trainer, count(*) from GYM group by trainer;
ii. update GYM set trainer= "SWS" where trainer="Sky";
select * from GYM;
iv. select * FROM GYM where YEAR(JOINED)=2021;
SET 6
Q1:
i.
import pandas as pd
apps = pd.DataFrame({"Appname" : ["Instagram",
"Spotify ","TikTok","Snapchat "] ,
"MAU" : [2000,574,1000,557],
"Dated" : ["2023-04-01","2023-08-11",
"2023-05-19","2023-12-15"]} ,
index = ["AP1","AP2","AP3","AP4"])
print(apps)
ii.
print(apps.loc[["AP1","AP4"]])
iii.
apps.loc["AP5"]=["YouTube", 2680,"2023-10-26"]
print(apps)
iv.
apps = apps.rename({"Dated":"Surveyed"} , axis = 1)
print(apps)
v.
import matplotlib.pyplot as plt
apps.plot.line("Appname","MAU")
plt.title("Apps Analysis")
plt.xlabel("Appname")
plt.ylabel("MAU")
plt.show()
Q2:
i. create table Training(Training_id varchar(2) primary key,Tname varchar(15),
Hours int,Charges int,Start_date date);
insert into Training values("T1","Data analytics",30,3000,"2024-01-15");
insert into Training values("T2","Machine learning",50,5000,"2023-12-30");
insert into Training values("T3","Data analytics",35,2500,"2023-11-21");
insert into Training values("T4","Cloud computing",45,3200,"2024-02-18");
insert into Training values("T5","Machine learning",60,4000,"2024-01-30");
insert into Training values("T6","Blockchain",30,2000,"2023-11-05");
select * from Training;
ii. select TName, Hours from Training where monthname(Start_date)='November';
iii. select Tname,sum(Charges) from Training group by Tname;
iv. update Training set Charges = Charges - Charges *(7/100) where Tname =
"Machine learning";
select * from Training;

You might also like