You are on page 1of 40

IP Practical File

Tushar Chopra 12th A


MATPLOTLIB

Data Visualisation
Q1. Write a python program to obtain the following information in two lists and prepare a line chart on the
information received.
Student Name- Aman, Satyam, karan, kashish
Height- 5’6, 5’8, 5’6, 5’3

Code:-
import matplotlib.pyplot as p
SN=["Aman","Satyam","Karan","Kashish"]
H=[5.6,5.8,5.6,5.3]
p.plot(SN,H)
p.show()

Output:-
Q2. Write a python program to obtain username and their age. Display a line chart to depict received information.
UN=”Surbhi”,”Sanshank”,”Gagandeep”,”Georgia”
Age= 10,12,5,6

Code:-
import matplotlib.pyplot as p
UN=["Surbhi","Sanshak","Gagandeep","Georgia"]
AGE=[10,12,5,6]
p.plot(UN,AGE)
p.show()

Output:-
Q3. Display a line chart to show the student’s score in English language.

Code:-
import matplotlib.pyplot as pp
d={"kartik":70,"Himanshi":72}
pp.title("English Score")
pp.xlabel("Student's Name")
pp.ylabel("English Marks")
pp.plot(d.keys(),d.values(),color="green",linestyle="dashdot")
pp.show()

Output:-
Q4. Display a line chart to show the student’s score in English and IP subject at least for five students.

Code:-
import matplotlib.pyplot as p
SN=["Amardeep","Varun","Avi","Kavya","Dhaarna"]
IP=[65,68,60,60,68]
ENG=[78,80,73,67,65]
p.title("Score English and IP")
p.xlabel("Student Name")
p.ylabel("Marks")
p.plot(SN,IP,color="Red",linestyle="dashdot")
p.plot(SN,ENG,color="Cyan",linestyle="dotted")
p.show()

Output:-
Q5. Write a python program to obtain 3 records of the students as student names and their height in two lists by the
user and prepare a bar chart on the information received by the user.

Code:-
import matplotlib.pyplot as p
SN=[]
H=[]

for i in range(1,4):
s=input("Enter your name: ")
h=float(input("Enter your height"))
SN.append(s)
H.append(h)

p.title("Student's Height Analysis")


p.xlabel("Student name")
p.ylabel("Student height")
p.bar(SN,H)
p.show()

Output:-
Q6. Write a python program to display a bar chart to receive the five username and their age thereafter depict this
information in the bar chart.

Code:-
import matplotlib.pyplot as p
UN=[]
A=[]

for i in range(1,6):
s=input("Enter username: ")
h=int(input("Enter your age"))
UN.append(s)
A.append(h)

p.title("User's Age")
p.xlabel("Username")
p.ylabel("Username's age")
p.bar(UN,A)
p.show()

Output:-
Q7. Prepare a horizontal bar chart depicting the score of four students in English subject.

Code:-
import matplotlib.pyplot as p
SN=[]
ES=[]

for i in range(1,5):
s=input("Enter your Name: ")
e=float(input("Enter your English marks: "))
SN.append(s)
ES.append(e)
p.title("English Score")
p.xlabel("Student's Name")
p.ylabel("Student's Marks")
p.barh(SN,ES,color="Red")
p.show()

Output:-
Q8. Obtain three students’ English and IP marks out of 100 and compare them in a double bar chart.

Code:-
import matplotlib.pyplot as p
import numpy as n

SN=[]
EM=[]
IP=[]

for i in range(1,5):
s=input("Enter your name: ")
m=float(input("Enter your English Marks: "))
w=float(input("Enter your IP marks: "))
SN.append(s)
EM.append(m)
IP.append(w)

SN_axis=n.arange(len(SN))

p.title("Marks Analysis")
p.xlabel("Student's Name")
p.ylabel("Marks")
p.bar(SN_axis+0.2,EM,0.4,label="Eng Marks",color="Red")
p.bar(SN_axis-0.2,IP,0.4,label="IP Marks",color="Cyan")
p.xticks(SN_axis,SN)
p.legend()
p.show()

Output:-
Q9. Write a python program to obtain the following information in two lists and prepare a line chart on the
information received.
Student Name- Aman, Satyam, karan, kashish
Height- 5’6, 5’8, 5’6, 5’3

Code:-
import matplotlib.pyplot as p
SN=["Aman","Satyam","karan","kashish"]
H=[5.6,5.8,5.6,5.3]

p.title("Height Analysis")
p.pie(H,labels=SN)
p.show()

Output:-
Q10. Write a python program to obtain a username and their age. Display a line chart to depict received
information.
UN=” Surbhi”,” Sanshank”,” Gagandeep”,” Georgia”
Age= 10,12,5,6

Code:-
import matplotlib.pyplot as p
UN=["Surbhi","Sanshank","Gagandeep","Georgia"]
AGE=[10,12,5,6]

p.title("Age Analysis")
p.pie(AGE,labels=UN)
p.show()

Output:-
Q11. Display a pie chart to show the student’s score in the English language.

Code:-
import matplotlib.pyplot as p
SN=["Avi","Amardeep","Chirag","Arpit","Ankush"]
ES=[56,80,45,32,68]

p.title("English Marks")
p.pie(ES,labels=SN)
p.show()

Output:-
Q12. Write a python program to obtain the following information in two lists and prepare a scatter chart on the
information received.
Student Name- Aman, Satyam, Karan, hashish
Height- 5’6, 5’8, 5’6, 5’3

Code:-
import matplotlib.pyplot as p

SN=["Aman","Satyam","Karan","Kashish"]
H=[5.6,5.8,5.6,5.3]

p.grid()
p.scatter(SN,H)

p.show()

Output:-
Q13. Write a python program to obtain a username and their age. Display a scatter chart to depict received
information.

Code:-
import matplotlib.pyplot as p

UN=["Surbhi","Shahsank","Gagandeep","Georgia"]
AGE=[10,12,5,6]

p.grid()
p.scatter(UN,AGE,color="Deepskyblue",linewidth=8)
p.xlabel("Username")
p.ylabel("User's Age")
p.title("Username Age Analysis")
p.show()

Output:-
Q14. Display a scatter chart to show the student’s score in the English language.

Code:-
import matplotlib.pyplot as p

SN=["Vansh","Gundeep","Kavya","Varun"]
M=[56,78,51,32]

p.scatter(SN,M,color="Springgreen",linewidth=8)
p.xlabel("Student's Name")
p.ylabel("English Marks")
p.title("Student's English Score")
p.show()

Output:-
Q15. Obtain students’ English and IP marks and compare them in a scatter chart.

Code:-
import matplotlib.pyplot as p

SN=["Vaibhav","Ankush","Pratham","Sahil"]
E=[63,80,36,45]
IP=[80,45,36,69]

p.grid()
p.scatter(SN,E,color="Springgreen",linewidth=8)
p.scatter(SN,IP,color="Mediumturquoise",linewidth=8)
p.xlabel("Student's Name")
p.ylabel("Marks")
p.title("English v/s IP Marks Analysis")
p.show()

Output:-
Q16. Obtain a student's name and their grades in IP subject to analyze the number of students in a particular
grade category.

Code:-
import matplotlib.pyplot as p SN=
["Gagan","Amandeep","Jaspal","Somil","Avi","Raman","Asha","Darshan","Dhwani","Rohit","Hameed"] IP=
[10,90,60,54,60,70.80,30,50,60,80]
EM=[50,90,75,45,50,40,10,90,80,50,60]
p.hist(IP,bins=[0,20,40,60,80,100],color="Blue")
p.hist(EM,bins=[0,20,40,60,80,100],color="red")
p.show()

Output:-
Box Plot
Q1. Write a python program to draw a box plot for the following data frame for the marks of IP subject for 5
students.
Sol:- Code:-
import matplotlib.pyplot as p

IP=[40,50,60,70]
p.boxplot(IP)
p.grid()
p.show()

Output:-
Q2. Write a python program to draw a box plot for the range of numbers 10-40.
Sol:- Code:-
import matplotlib.pyplot as p
import numpy as pp
IP=pp.arange(10,41)
p.boxplot(IP)
p.grid()
p.show()

Output:-
PANDAS
Q1. Create a data series of Weekdays name

Code:-
import pandas as pp WD=
["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
S=pp.Series(WD,index=[1,2,3,4,5,6,7])
print(S)

Output:-

Q2. Create a python series for the following output with the help of List and Dictionaries components separately in
different programs.

By using List-
Code:-
import pandas as pp

N=["Aman","Dhawani"]

D=pp.Series(N,index=["A","B"])

print(D)

Output:-
By using Dictionary-
Code-
import pandas as pp N=
{"A":"Aman","B":"Dhawani"}
D=pp.Series(N)
print(D)

Output:-

Q3. Convert the following program to take values using a list .


import numpy as np
import pandas as pd

array1=np.array([1,2,3,4])

series3=pd.Series(array1)

print(series3)

Solution-
Code:-
import pandas as p
N=[1,2,3,4]
series3=p.Series(N)
print(series3)

Output:-

Q6.Write a python program to create a data series of the following data values:
Row 1 India
Row 2 Bangladesh
Row 3 Nepal
Row 4 Sri Lanka
a)Write a python statement to display Sri Lanka
b)Display Nepal and Sri Lanka
c)Display Bangladesh
Solution:-
a)Code:-
import NumPy as np
import pandas as pp
CN=["India","Bangladesh","Nepal","Sri Lanka"]
series3=pp.Series(CN,index=["Row 1","Row 2","Row 3","Row 4"])
print(series3["Row 4"])

Output:-

b) Code:-
import numpy as np
import pandas as pp
CN=["India","Bangladesh","Nepal","Sri Lanka"]
series3=pp.Series(CN,index=["Row 1","Row 2","Row 3","Row 4"])
print(series3["Row 3"::])

Output:-

c) Code:-
import numpy as np
import pandas as pp
CN=["India","Bangladesh","Nepal","Sri Lanka"]
series3=pp.Series(CN,index=["Row 1","Row 2","Row 3","Row 4"])
print(series3["Row 2"])

Output:-
Q7. Write a python program to create a data series of the following data values.
India Delhi
Bangladesh Dhaka
Nepal Kathmandu
Sri Lanka Sri Jaywardenepura
a)Display the capital of India.
b)Display the capital of Nepal and Bangladesh.

a) Code:-
import pandas as pp
CN=["Delhi","Dhaka","Kathmandu","Sri Jaywardeneura"]
series3=pp.Series(CN,index=["India","Bangladesh","Nepal","Sri Lanka"])
print(series3["India"])

Output:-

b) Code:-
import pandas as pp
CN=["Delhi","Dhaka","Kathmandu","Sri Jaywardeneura"]
series3=pp.Series(CN,index=["India","Bangladesh","Nepal","Sri Lanka"])
print(series3["Bangladesh":"Nepal"])

Output:-

Q8. Write a python program to create two data series and perform the following mathematical operations on it.
Salary:-
Rohit 40000
Farhan 45000
John 35000
Dev 50000
Commission:-
Rohit 14000
Farhan 14000
John 15000
Dev 10000
a)Display net salary dev is receiving.
b)Display net salary of all the employees.
Solution:-
a) Code:-
import pandas as pp E=pp.Series([40000,45000,35000,50000],index=
["Rohit","Farhan","John","Dev"])
ES=pp.Series([14000,14000,15000,10000],index=
["Rohit","Farhan","John","Dev"]) print("Net salary of All Employees")

print(E+ES)

Output:-

b) Code:-
import pandas as pp E=pp.Series([40000,45000,35000,50000],index=
["Rohit","Farhan","John","Dev"])
ES=pp.Series([14000,14000,15000,10000],index=
["Rohit","Farhan","John","Dev"]) print("Net salary of Dev")

print(E["Dev"]+ES["Dev"])

Output:-
Q9. Write a python program to display the following data frame:-

Code:-import pandas as pp
import NumPy as np S={2014:[100.5,150.8,200.9,30000,40000],2015:
[12000,18000,22000,30000,45000], 2016:
[20000,50000,70000,10000,125000],2017:
[50000,60000,70000,80000,90000]} df=pp.DataFrame(S,index=
("Madhu","Kusum","Kinshuk","Ankit","Shruti"))

print(df)

Output:-
Q10. Write a python program to do the following changes to the following Data Frame.

a) Change the column values of 2014 as 100,150,200,250,300.


b) Change the name of 2017 to “The Year 2017”.
c) Update all data values of Ankit as 300 for all column values.
d) Remove column 2017 and record of Kusum.
Sol:-
a) Code:-
import pandas as pp
import NumPy as np S={2014:[100.5,150.8,200.9,30000,40000],2015:
[12000,18000,22000,30000,45000], 2016:
[20000,50000,70000,10000,125000],2017:
[50000,60000,70000,80000,90000]} df=pp.DataFrame(S,index=
("Madhu","Kusum","Kinshuk","Ankit","Shruti")) df[2014]=[100,150,200,250,300]
print(df)

Output:-

b) Code:-
import pandas as pp
import NumPy as np S={2014:[100.5,150.8,200.9,30000,40000],2015:
[12000,18000,22000,30000,45000], 2016:
[20000,50000,70000,10000,125000],2017:[50000,60000,70000,80000,90000]}
df=pp.DataFrame(S,index=("Madhu","Kusum","Kinshuk","Ankit","Shruti"))
df=df.rename({2017:"Year 2017"}, axis=1)
print(df)
Output:-

c) Code:-
import pandas as pp
import NumPy as np S={2014:[100.5,150.8,200.9,30000,40000],2015:
[12000,18000,22000,30000,45000], 2016:
[20000,50000,70000,10000,125000],2017:
[50000,60000,70000,80000,90000]} df=pp.DataFrame(S,index=
("Madhu","Kusum","Kinshuk","Ankit","Shruti")) df.loc['Ankit']=[300,300,300,300]
print(df)

Output:-

d) Code:-
import pandas as pp
import NumPy as np S={2014:[100.5,150.8,200.9,30000,40000],2015:
[12000,18000,22000,30000,45000], 2016:
[20000,50000,70000,10000,125000],2017:
[50000,60000,70000,80000,90000]} df=pp.DataFrame(S,index=
("Madhu","Kusum","Kinshuk","Ankit","Shruti")) df=df.drop([2017], axis=1)
df=df.drop(['Kusum'], axis=0)
print(df)

Output:-
Q11. Create a dataframe for 5 students' results in the subject IP, Accounts, and BST. Provide boolean indexing for
the data frame.
Sol:-
Code-
import pandas as p
S={"ip":[90,80,70,15,30],"accts":[50,60,70,90,60],"bst":[50,60,70,30,10]}

df=p.DataFrame(S,columns=["ip", "accts", "bst"],index=[True, False, True, False, True])


print(df)

Output-
MY SQL
Q1. Create a student table with the student ID, Name, and marks as attributes where the student ID is the
primary key.
Sol. Code- create table STUDENT
(
studentID Int Primary key,
name varchar(40),
marks Int
);
Output-
Q2. Insert the details of a new student in the above table.
Sol. Code- insert into STUDENT values (123, "Amardeep Singh", 90);
insert into STUDENT values (456, "Harkirat Singh", 95);
insert into STUDENT values (789, "Avi Tuteja", 65);
Output-

Q3. Delete the details of a student in the above table. Sol.


Code- delete from STUDENT Where studentid=789;
Output-
Q4. Use the select command to get the details of the students with marks more than 80.
Sol. Code- Select * from STUDENT Where marks<80;
Output-

Q5. Find the minimum, maximum, sum, and an average of marks in the student table.
Sol. Code-a) Select MAX(MArks) from STUDENT;
b) Select MIN(Marks) from STUDENT;
c) Select AVG(Marks) from STUDENT;
Output- a)
b)

c)
Q6. Find the total number of customers from each country in the table (customerID, customer name,
country) using group by.
Sol. Code-Select Count(customerID), Country From TOURIST
group by Country;
Output-

Q7. Write a SQL query to order the (student ID, marks) table in descending order of the marks. Sol.
Code- Select studentID, marks from STUDENT
ORDER BY marks DESC;
Output-
Q8. Add new column results in the student table.
Sol. Code- Alter table STUDENT
Add results Varchar(40)
After marks;
Output-

Q9. Change the results of students as ‘First division” who have scored more than 60. Sol.
Code-Update STUDENT
set resluts = "First Division"
Where marks<60;
Output-
Q10. Delete column results from students table.
Sol. Code- Alter table STUDENT
Drop column results;
Output-

Q11. Show the current database in use.


Sol. Code-SELECT DATABASE() FROM DUAL;
Output-
Q12. Show all the table names of the current used database.
Sol. Code- SHOW TABLES;
Output-

You might also like