Professional Documents
Culture Documents
Xiiip Practical 2023-24 - Final
Xiiip Practical 2023-24 - Final
===================================
Practical MANUAL
===================================
*******INDEX*******
S. Page
Date No.
No. Aim/Practical
1. Write a python program to create a series to print scalar value “5” five
times.
2. Write a python program to create a series object house using a
dictionary that stores the number of students in each house of CLASS
12B of your school.
Note: Assume four house names are Raman, Shivaji, Ashok and Tagor
having 34, 42, 29, 58 students respectively.
16. Write a program to create a horizontal bar chart for India's medal tally.
Australia 80 59 59 198
England 45 45 46 136
India 26 20 20 66
Canada 15 40 27 82
Manisha has created following table named exam:
17.
Help her in writing SQL queries to the perform the following task:
i. Insert a new record in the table having following values:
[6,'Khushi','CS',85]
ii. To change the value “IP” to “Informatics Practices” in subject
column.
iii. To remove the records of those students whose marks are less than
30 .
iv. To add a new column Grade of suitable datatype.
v. To display records of “Informatics Practices” subject.
Create a student table with the student id, name and marks as
21. attributes where the student id is the primary key.
Delete the details of a student in the above table whose marks are
23. less than 40.
Use the select command to get the details of the students with
24. marks more than 80.
Find the min, max, sum and average of the marks in a student
25. marks table.
CODE:
import pandas as pd
num=pd.Series(5, index=[1,2,3,4,5])
print (num)
OUTPUT
PRACTICAL-2
DATE:
========================================
AIM: Write a program to create a series object house using a dictionary that stores the
number of students in each house of CLASS 12B of your school.
Note: Assume four house names are Raman, Shivaji, Ashok and Tagor having 34, 42, 29,
58 students respectively.
========================================
CODE:
import pandas as pd
d={"Raman" :34, "Shivaji" :42, "Ashok" :29, "Tagor" :58}
house=pd.Series(d)
print(house)
OUTPUT
PRACTICAL-3
DATE:
========================================
AIM: Write a program to create a series object comp using a list that stores the
number of quantity of computer item in lab of your school.
Note: Assume four computer item names as index are KB, Mouse, computer and printer
having values are 30, 25, 20, 2 items respectively
========================================
CODE:
import pandas as pd
i=['KB', 'Mouse', 'computer’,'printer']
l=[30, 25, 20, 2]
comp=pd.Series(data=l, index=i)
print(comp)
OUTPUT
PRACTICAL-4
DATE:
========================================
AIM: Write a python program to create a Series to store total 6 name of student as key
along with Percentage as value using dictionary and print all the elements that are above
75 percentage.
========================================
CODE:
import pandas as pd
d={"Raksha" :76, "Mayuri" :82, "Namrata" :65, "kamlesh"
:68,"Ashish":90,"Vivek":80}
s=pd.Series(d)
print(s)
print("List of student having Percentage more than 75")
print(s[s>75])
OUTPUT
PRACTICAL-5
DATE:
========================================
AIM: Write a python program to perform following mathematical Operations on Two
Series objects: (i) Addition (ii) Subtraction (iii) Multiplication (iv) Division.
S1 S2
========================================
CODE:
import pandas as pd
s1=pd.Series([12,14,16,18])
s2=pd.Series(5,index=[0,1,2,3])
print(s1)
print(s2)
print("**Addition**")
print(s1+s2)
print("**Subtraction**")
print(s1-s2)
print("**Multiplication**")
print(s1*s2)
print("**Division**")
print(s1/s2)
OUTPUT
PRACTICAL-6
DATE:
========================================
AIM: Write python program to create series and display various
attribute of Series .
========================================
CODE:
import pandas as pd
import numpy as np
s1 = pd.Series([5700,1200,500,640,np.NaN], index=['A', 'B', 'C',
'D', 'E'])
s2 = pd.Series([110,410,120,454], index=['A', 'B', 'C', 'D'])
print(s1)
print(s2)
print("Attribute Name Series 1 Series 2")
print("======================================
====")
print("Data Type ", s1.dtype, "\t\t", s2.dtype)
print("Shape ", s1.shape, "\t\t\t", s2.shape)
print("No.ofBytes ", s1.nbytes, "\t\t\t", s2.nbytes)
print("No.ofDimensions",s1.ndim,"\t\t\t",s2.ndim)
print("Item Size ",s1.size,"\t\t\t",s2.size)
print("Has Nans? ",s1.hasnans,"\t\t\t",s2.hasnans)
print("Empty ",s1.empty,"\t\t\t",s2.empty)
OUTPUT
PRACTICAL-7
DATE:
========================================
AIM: Write a Python code to create a DataFrame stock with appropriate column
headings from the list given below:
[[101,'Gurman',98], [102,'Rajveer',95], [103,'Samar' ,96], [104,'Yuvraj',88]]
========================================
CODE:
import pandas as pd
d=[[101,'Gurman',98],[102,'Rajveer',95],[103,'Samar'
,96],[104,'Yuvraj',88]]
c=['sno','Name','Score']
stock=pd.DataFrame(d,columns=c)
print(stock)
OUTPUT
PRACTICAL-8
DATE:
========================================
AIM: Write a Python code to create a DataFrame ‘Stock’ by using dictionary method:
Name Price
0 Nancy Drew 150
1 Hardy boys 180
2 Diary of a wimpy kid 225
3 Harry Potter 500
========================================
CODE:
import pandas as pd
d={'Name':['Nancy Drew','Hardy boys','Diary of a wimpy kid','Harry
Potter'],'Price':[150,180,225,500]}
stock =pd.DataFrame(d)
print(stock)
OUTPUT
PRACTICAL-9
DATE:
========================================
AIM: Write a Python code to create a DataFrame with appropriate column headings from
the csv file given below:
city Maxtemp Mintemp Rainfall
0 Delhi 40 32 24.1
1 Bengaluru 31 25 36.2
2 Chennai 35 27 40.8
3 Mumbai 29 21 35.2
========================================
CODE:
import pandas as pd
df=pd.read_csv(r"C:\Users\rasha\OneDrive\Desktop\a.csv")
print(df)
OUTPUT
PRACTICAL-10
DATE:
========================================
AIM: Write a Python code to create a DataFrame ‘lib’ by using Series method:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
========================================
CODE:
import pandas as pd
s1=pd.Series(['P01','P02','P03','P03'])
s2=pd.Series([40,31,35,29])
s3=pd.Series([85,76,129,730])
s4=pd.Series([500,200,50,70])
d={'Pcd':s1,'title':s2, 'Price':s3, 'qty':s4}
lib=pd.DataFrame(d)
print(lib)
OUTPUT
PRACTICAL-11
DATE:
========================================
AIM: Consider the given DataFrame:
Pcd title Price qty
0 P01 Notebook 85 500
1 P02 Pencilbox 76 200
2 P03 WaterBottle 129 50
3 P04 SchoolBag 730 70
Write suitable Python statements for the following:
i. Add a column called ACC_NO with the following data:
[135,153,225,442].
ii. Add a new Record
iii. Remove the column qty.
iv. Remove first and third rows from DataFrame
========================================
CODE:
import pandas as pd
s1=pd.Series(['P01','P02','P03','P03'])
s2=pd.Series(["Note Book","Pencil Box","Water bottle","School
bag"])
s3=pd.Series([85,76,129,730])
s4=pd.Series([500,200,50,70])
d={'Pcd':s1,'title':s2, 'Price':s3, 'qty':s4}
lib=pd.DataFrame(d)
print(lib)
lib["ACC_NO "]=[135,153,225,442]
lib.loc[4]=["p05","bigbook",20,20,501]
print(lib)
lib.drop(["qty"],axis=1,inplace=True)
print(lib)
lib.drop([0,2],axis=0,inplace=True)
print(lib)
OUTPUT
PRACTICAL-12
DATE:
========================================
AIM: Consider the following dataframe: student_df
Name CLASS marks
Anamay XI 95
Aditi XI 82
Mehak XI 65
Kriti XI 45
12. Write a statement to get the minimum value of the column marks.
13. Write a statement to get the maximum value of the column marks.
14. Write a statement to get the sum value of the column marks.
15. write a statement to get the average value of the column marks.
16. Write a statement to get Transpose of DataFrame student_df.
17. Write a statement to get the sorted value of the column marks.
18. Write a statement to get the sorted value of the column name ascending.
19. Write a statement to get the sorted value of the column name descending.
20. Write a statement to get the sort index of DataFrame.
Write a statement to get the sorted column index of DataFrame.
========================================
CODE:
Consider the following DataFrame: student_df
Name CLASS marks
Anamay XI 95
Aditi XI 82
Mehak XI 65
Kriti XI 45
1.Write a statement to get the minimum value of the column
marks.
>>> student_df["marks"].min()
45
student_df.sort_values(by=["Name"],ascending=False)
Name CLASS marks
2 Mehak XI 65
3 Kriti XI 45
0 Anamay XI 95
1 Aditi XI 82
CODE:
1.To add DataFrames df1 and df2.
df1+df2
mark1 mark2
0 40 35
1 60 70
2 35 60
3 90 100
df2-df1
mark1 mark2
0 20 5
1 -20 -20
2 5 0
3 10 -40
9.To change the column heading of df1 to m11 for mark1 and
m12 for mark2
df1.columns=["m11","m12"] # changes in original variable
>>> df1
m11 m12
0 30 20
1 20 25
2 20 30
3 40 10
4 50 30
OUTPUT
PRACTICAL-14
DATE:
========================================
2. AIM: Plot the following data using a line plot:
• Before displaying the plot display “Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday, Sunday” in place of Day 1, 2, 3, 4, 5, 6, 7
• Change the color of the line to ‘Magenta’.
========================================
CODE:
import pandas as pd
import matplotlib.pyplot as plt
x=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
y=[2000,2800,3000,2500,2300,2500,1000]
plt.plot(x,y,color="magenta",marker="*", label="No. of tickets")
plt.title("Day wise Tickets sold ")
plt.xlabel("Days")
plt.ylabel("No of tickets sold")
plt.legend()
plt.grid(True)
plt.savefig("d:\ Tickets.jpg")
plt.show()
OUTPUT
PRACTICAL-15
DATE:
========================================
2. AIM: Collect the minimum and maximum temperature of your city for a month and
present it using a histogram plot.
========================================
CODE:
import pandas as pd
import matplotlib.pyplot as plt
min_temp=[6,5,6,5,5,5,4,9,11,12,14,15,12,13,11,11,8,7,10,10,9,9
,7,8,9,5,6,6,7,10]
max_temp=[16,15,15,16,18,19,15,14,18,27,17,20,17,18,15,16,14,
17,20,17,18,15,16]
plt.hist(min_temp,bins=5,color="brown",edgecolor="black")
plt.title("Minimum Temperatures in city During Fenruary 2021")
plt.ylabel("Frequency")
plt.xlabel("Temperature")
plt.show()
OUTPUT
PRACTICAL-16
DATE:
========================================
AIM: Write a program to create a horizontal bar chart for India's medal tally.
Country Gold Silver Bronze Total
Australia 80 59 59 198
England 45 45 46 136
India 26 20 20 66
Canada 15 40 27 82
========================================
CODE:
import matplotlib.pyplot as plt
Info = ['Gold', 'Silver', 'Bronze', 'Total']
India = [26, 20, 20, 66]
plt.ylabel("Medal type")
plt.xlabel("Medal count")
plt.title("India's Medal Tally in Commonwealth 2018")
X = range (len (Info))
plt.barh(X, India, color = ['gold', 'silver', 'brown', 'black'])
plt.show()
OUTPUT
PRACTICAL-17
DATE:
========================================
AIM:
Help him in writing SQL queries to the perform the following task:
i. Insert a new record in the table having following values:
[6,'Khushi','CS',85]
ii. To change the value “IP” to “Informatics Practices” in subject
column.
iii. To remove the records of those students whose marks are less than
30 .
iv. To add a new column Grade of suitable datatype.
v. To display records of “Informatics Practices” subject.
========================================
CODE:
i. INSERT INTO EXAM VALUES(6,'Khushi','CS',85);
ii. UPDATE EXAM SET subject= "Informatics
Practices" where subject = "IP";
iii. DELETE FROM EXAM WHERE marks<30;
iv. ALTER TABLE EXAM ADD COLUMN grade varchar(2);
v. Select * from exam where subject="Informatics
Practices";
OUTPUT
PRACTICAL-18
DATE:
========================================
AIM:
SQL QUERIES
Rasha creates a table STOCK to maintain computer stock in vidyalaya. After
creation of the table, she has entered data of 8 items in the table.
Table : STOCK
(v) Delete the record of stock which were purchased before year 2015.
(vi) Add a column STATUS in the table with datatype as char with 1 characters
========================================
CODE:
(i) stockid
(ii) degree = 8, cardinality = 3
(iii) (a) insert into stock values(201,’2022-10-18’,’neckphone’,’boat’,500);
(iv) update stock set price=price*0.95 where
year(dopurchase)=2020;
(v) delete from stock where year(dopurchase) < 2015;
(vi) alter table stock add column STATUS char(1);
PRACTICAL-19
DATE:
========================================
AIM:
========================================
CODE:
i. SELECT POWER(3,4);
ii. SELECT NOW();
iii.SELECT ROUND(-34.4567,2);
iv. SELECT TRIM(USERID) FROM USER;
v. SELECT LENGTH("FIFA World Cup");
PRACTICAL-20
DATE:
========================================
AIM: Freya Perform the following operations in MySQL using SQL command
A.Create a table emp with attributes empno, ename, salary
B. Add following columns using alter table command
Age
City
MobileNo
C Add primary key to the above table.
D Change the data type size of salary column.
E Remove the column 'City' and ‘MobileNo’ from the above table.
F Show the structure of table emp.
========================================
CODE:
(a)create table emp
(
empno int,
ename varchar(30),
salary int
);
(b)ALTER TABLE EMP ADD
(
AGE INT(2),
CITY VARCHAR(30),
MOBILENO CHAR(10)
);
(c) ALTER TABLE EMP ADD PRIMARY KEY(EMPNO);
(d) ALTER TABLE EMP MODIFY COLUMN SALARY FLOAT(7,2);
(e) ALTER TABLE EMP DROP COLUMN CITY, DROP COLUMN MOBILENO;
(F) DESCRIBE EMP;
PRACTICAL-21
DATE:
========================================
AIM: Create a student table with the student id, name and marks as attributes
where the student id is the primary key.
========================================
Code :
CREATE TABLE STUDENT
(STUDENT_ID INT PRIMARY KEY,
SNAME VARCHAR(20),
MARKS INT);
PRACTICAL-22
DATE :
========================================
AIM: Insert the details of 5 students in the above table
========================================
Code :
INSERT INTO STUDENT VALUES(1011,’AJAY’, 55);
INSERT INTO STUDENT VALUES(1023,’SEENA’, 70);
INSERT INTO STUDENT VALUES(1045,’ROMIL’, 95);
INSERT INTO STUDENT VALUES(1019,’SMITH’, 36);
INSERT INTO STUDENT VALUES(1052,’LAKSHYA’, 88);
PRACTICAL – 23
DATE :
========================================
AIM : Delete the details of a student in the above table Whose marks are less
than 40.
========================================
Code:
DELETE FROM STUDENT
WHERE MARKS < 40;
PRACTICAL – 24
DATE :
========================================
AIM : Use the select command to get the details of the students with marks
more than 80.
========================================
Code:
SELECT * FROM STUDENT
WHERE MARKS > 80;
PRACTICAL – 25
DATE :
========================================
AIM : Find the min, max, sum and average of the marks in a student marks
table.
========================================
Code:
SELECT MIN(MARKS), MAX(MARKS),SUM(MARKS), AVG(MARKS) FROM STUDENT;
PRACTICAL – 26
DATE :
========================================
AIM : Find the total number of customers from each country in the
table(customer id, customer name, country) using group by.
========================================
Code:
SELECT COUNTRY, COUNT(*) FROM CUSTOMER
GROUP BY COUNTRY;
PRACTICAL – 27
DATE :
========================================
AIM : Write a SQL query to order the (student id, marks) table in aescending
order of the marks.
========================================
Code:
SELECT * FROM STUDENT
ORDER BY MARKS ASC;