Ip Practicals
Ip Practicals
PALAKKAD
SESSION:- 2023-24
INFORMATICS PRACTICES
SUB.CODE- 065
PRACTICAL FILE
NAME:_____________________________
Data visualization
Display line chart with suitable label.
16
Display line chart with suitable label
using marker, markeredgecolor, color
17 and label.
20 MySQL QUERIES
21 MySQL JOINS
Teacher's Signature
___________________________________
OUTPUT:
PYTHON
PRACTICAL NO.1:
Aim:Create a panda's saves from dictionary of values and andarray. This
generates a series using one-dimensional array and display the following
output:
0 10
1 20
2 20
3 40
4 50
SOURCE CODE:
import pandas as pd
importnumpy as np
d={0:10, 1:20, 2:30, 3:40, 4:50}
s=pd.Series(d)
array1= np.array ([10,20,30,40,50])
s1= pd.Series(array1)
print (s,s1)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.2:
Aim: Create a pandas data frame series from a dictionary of values and a
ndarray This generates a series wing one-dimensional array and display
the following output:
A 20
B 40
C 60
D 80
E 100
SOURCE CODE:
import pandas as pd
importnumpy as np
a=np.array([20, 40, 60, 80, 100])
df=pd.DataFrame (a, index=['A','B','C','D','E'])
print(df)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.3:
Aim:Create a series with index as emp-name and salary as values from the
given set ‘employee’
SOURCE CODE:
import pandas as pd
ename = ['Jeni', 'Karan', 'Priya', 'Kamal', 'Santha','Vimal']
salary = [24000, 20000, 18000, 18900, 17000,15000]
s=pd.Series(salary, index=ename)
print(s)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.4:
SOURCE CODE:
import pandas as pd
ename = ['Jeni', 'Karan', 'Priya', 'Kamal', 'Santha','Vimal']
salary = [24000, 20000, 18000, 18900, 17000,15000]
s=pd.Series(salary, index=ename)
print (s[s>18000])
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.5:
Aim: Create a data frame using dictionary of lists with its elements
representing students and marks.
Stname ACCOUNTAN IP ECONOMIC
CY S
Adithya 94 97 90
Abinav 98 99 89
Ajay 99 87 80
Ashwin 83 89 78
Abhijth 99 99 99
SOURCE CODE:
import pandas as pd
stud = {'stname':['Adithya', 'Abinav', 'Ajay', 'Ashwin','Abhijith'],
' Accountancy': [94, 98, 99, 83, 94],
'IP': [97, 99, 87, 89, 99],
'Economics': [90, 89, 80, 78, 99]}
df=pd.DataFrame(stud)
print(df)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO 6:
Aim: Create a data frame using dictionary of series with its elements
representing students and their marks.
Stname ACCOUNTANC IP ECONOMICS
Y
Adithya 94 97 90
Abinav 98 99 89
Ajay 99 87 80
Aswin 83 89 78
Abhijth 99 99 99
SOURCE CODE:
import pandas as pd
nm=pd.Series(['Adithya','Abinav','Ajay','Ashwin','Abhijith'])
acc=pd.Series([94, 98, 99, 83, 99])
ip=pd.Series([97, 99,87, 89, 99])
eco = pd.Series([90, 89, 80, 78, 99])
stud=pd.DataFrame({'stname':nm,'Accountancy': acc, 'IP' : ip,'Economics':
eco})
print(stud)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.7:
Aim: Create a Data Frame for exam results and display row labels, column
labels, datatype of each column and dimension.
Stname Maths IP Physics Total
Krishna 94 89 90 267
Abishek 88 99 99 230
Ajay 80 80 79 248
Kiran 83 81 76 248
Jithu 89 88 90 267
SOURCE CODE:
import pandas as pd
r={'Stname':['Krishna','Abishek','Ajay','Kiran','Jithu'],
'Maths':[94, 88, 80, 83, 89],
'IP':[89, 99, 80, 81, 88],
'Physics':[90, 99, 79, 76, 90],
'Total':[267, 230, 248, 248, 267]}
df = pd.DataFrame(r)
print(df)
print (df.columns)
print (df.dtypes)
print (df.shape)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.8:
Aim: Create a data frame sales where each row contains the item category,
item name and expenditure. Display records from the first to the third row.
Item category Item name Expenditure No of items
200 Plate 80 15
201 Glass 35 20
202 Vessel 500 5
201 Box 350 14
204 Jar 200 10
SOURCE CODE:
import pandas as pd
sales={'Item category':[200, 201, 202, 201, 204],
'Item-name':['Plate','Glass', 'Vessel', 'Box', 'Jar'],
'Expenditure':[80, 35, 500, 350, 200],
'No of items':[15, 20, 5, 14, 10]}
df=pd.DataFrame(sales)
print (df)
print(df[1:4])
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.9:
Aim: Create a data frame sales where each row contains the item category,
item name and expenditure. Group the rows by the category and print the
total expenditure per category
Item category Item name Expenditure No of item
200 Plate 80 15
201 Glass 35 20
202 Vessel 500 5
201 Box 350 14
204 Jar 200 10
SOURCE CODE:
import pandas as pd
sales={'Item category':[200, 201, 202, 201, 204],
'Item-name':['Plate','Glass', 'Vessel', 'Box', 'Jar'],
'Expenditure':[80, 35, 500, 350, 200],
'No of items':[15, 20, 5, 14, 10]}
df=pd.DataFrame(sales)
df1=df.groupby('Item category')
df2=df1['Expenditure'].sum()
print (df2)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.10:
Aim: Create a data frame sales where each row contains the item category,
item name and expenditure. Display item name and expenditure.
Item category Item name expenditure
200 Plate 80
201 Glass 35
202 Vessel 500
201 Box 350
204 Jar 200
SOURCE CODE:
import pandas as pd
sales={'Item category':[200, 201, 202, 201, 204],
'Item-name':['Plate','Glass', 'Vessel', 'Box', 'Jar'],
'Expenditure':[80, 35, 500, 350, 200]}
df=pd.DataFrame(sales)
print (df)
print ()
print(df.iloc[:,1:])
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.11:
Aim: Create a data frame sales where each row contains the item category,
item name , expenditure and no of items. Display last two records.
Item category Item name Expenditure No of item
200 Plate 80 15
201 Glass 35 20
202 Vessel 500 5
201 Box 350 14
204 Jar 200 10
SOURCE CODE:
import pandas as pd
sales={'Item category':[200, 201, 202, 201, 204],
'Item-name':['Plate','Glass', 'Vessel', 'Box', 'Jar'],
'Expenditure':[80, 35, 500, 350, 200],
'No of items':[15, 20, 5, 14, 10]}
df=pd.DataFrame(sales)
print (df)
print(df.tail(2))
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.12:
Aim: Create a data frame sales where each row contains the item category,
item name, expenditure and no of items. Replace the item name to jug and
expenditure of jar to 150.
Item category Item name Expenditure No of item
200 Plate 80 15
201 Glass 35 20
202 Vessel 500 5
201 Box 350 14
204 Jar 200 10
SOURCE CODE:
import pandas as pd
sales={'Item category':[200, 201, 202, 201, 204],
'Item-name':['Plate','Glass', 'Vessel', 'Box', 'Jar'],
'Expenditure':[80, 35, 500, 350, 200],
'No of items':[15, 20, 5, 14, 10]}
df=pd.DataFrame(sales)
print (df)
df.loc[4,'Expenditure']=150
df.loc[4,'Item-name']='Jug'
print(df)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.13:
Aim: Create a data frame of salary of three employees and add 2000 as
bonus.
SOURCE CODE:
import pandas as pd
sal={'Empid':[101 ,102 ,103],
'Empname':['Jay','Rithu','Harsh'],
'Salary':[20000,30000,28000]}
df=pd.DataFrame(sal)
print(df)
df['Salary']=df['Salary']+2000
print(df)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.14:
Aim: Create a data frame of [10,20],[22],[30,40,50] and do the following
a) Display the data frame. Notice that the missing value is represented
by NaN.
b) Replace the missing value with 0.
SOURCE CODE:
import pandas as pd
d=[[10,20],[22],[30,40,50]]
df=pd.DataFrame(d)
print(df)
df.fillna(value=0,inplace=True)
print(df)
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.15:
Aim: Consider the following stud.csv file containing the data given below.
Stname Maths IP Physics Chemistry
Krishna 94 89 90 89
Abishek 88 99 99 78
Ajay 80 80 70 98
Kiran 83 87 78 90
Jithu 89 88 90 80
a) Read the csv file into a data frame df which is stored with tab (‘\t’)
separator.
b)Write the code to find total marks for each student.
SOURCE CODE:
import pandas as pd
df=pd.read_csv('C:\\Users\\HP\\OneDrive\\Desktop\\NOTES\\stud.csv')
print(df)
#To display the total marks of each student
df['Total']=df['Maths']+df['IP']+df['Physics']+df['Chemistry']
print(df)
CONCLUSION:
The program was successfully completed.
OUTPUT:
DATA VISUALISATION
PRACTICAL NO.16:
Aim: Display a line chart with a suitable label in the X-axis,Y-axis, line
width, label and color. Use the following data.
X=[2,3,4,5,6]
Y=4X
SOURCE CODE:
importmatplotlib.pyplot as plt
importnumpy as np
X=np.arange(2,7)
plt.plot(X,X*4,lw=4,label='Line1',color='r')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.legend()
plt.show()
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.17:
Aim: Display a line chart with a suitable label in the X-axis,Y-axis, line
style, marker, marker edge color label and color. Use the following data.
X=[2,3,4,5,6]
Y=[4,6,8,10]
SOURCE CODE:
importmatplotlib.pyplot as plt
importnumpy as np
X = [2,3,4,5,6]
Y = [4,6,8,10,12]
plt.plot(X,Y,marker='*',markeredgecolor='r',color='b',ls=':',lw=3,
markersize=10,label='line1')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.show()
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.18:
Aim: Display a multiple bar chart of the number of students in a class.
CLASS IX X XI XII
SECTION 40 35 48 50
A
SECTION 34 38 40 45
B
SOURCE CODE:
importmatplotlib.pyplot as plt
import pandas as pd
data={'SECTION A':[40,35,48,50],
'SECTION B':[34,38,40,45]}
df=pd.DataFrame(data,index=['IX','X','XI','XII'])
df.plot(kind='bar')
plt.title('Strength Analysis of Students')
plt.xlabel('Classes')
plt.ylabel('Strength')
plt.show()
CONCLUSION:
The program was successfully completed.
OUTPUT:
PRACTICAL NO.19:
Aim:Display a Histogram chart of the student’s height and weight. Given
the set of data.
Name: Shiv, Rithika, Sanju, Kamal, Radu, Abi
Weight: 60,6
1,65,70,72,56
Height: 56,60,73,75,80,84
SOURCE CODE:
importmatplotlib.pyplot as plt
import pandas as pd
stud=['Shiv', 'Rithika', 'Sanju', 'Kamal', 'Radu', 'Abi']
weight=[60, 61, 65, 70, 72, 56]
height=[56, 60, 73, 75, 80, 84]
df=pd.DataFrame({'height':height,'weight':weight},index=stud)
df.plot(kind='hist')
plt.show()
OUTPUT:
Query OK, 0 rows affected, 4 warnings (0.93 sec)
OUTPUT:
Query OK, 1 row affected (0.12 sec)
Query OK, 1 row affected (0.38 sec)
Query OK, 1 row affected (0.11 sec)
Query OK, 1 row affected (0.11 sec)
Query OK, 1 row affected (0.11 sec)
DATABASE QUERY
PRACTICAL NO.20: MySQL Queries
1.Aim: Create a table Student with Student number, Name, Class, Date
of birth, Gender, City.
QUERY:
mysql>CREATE TABLE Student (Stno INT(3) PRIMARY KEY,
Name VARCHAR(20), Class INT(4), DOB Date,Gender CHAR(1),
City VARCHAR(20), Deptno INT(4)Marks INT(3));
OUTPUT:
Query OK, 0 rows affected, 1 warning (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 1
3. Aim: Delete the 3rd column from the above table.
QUERY:
mysql> ALTER TABLE Student
DROP Class;
mysql> SELECT * FROM Student;
OUTPUT:
OUTPUT:
5. Aim: To display the details of student between Stno 2 and 5.
QUERY:
mysql> SELECT * FROM Student
WHERE Stno BETWEEN 2 AND 5;
7. Aim: Find the minimum, maximum, sum and average of marks from the
Student table.
QUERY:
mysql> SELECT MAX(Marks) AS 'MAX', MIN(Marks) AS 'MIN',
SUM(Marks) AS 'SUM', AVG(Marks) AS 'AVG'
FROM Student;
OUTPUT:
OUTPUT:
OUTPUT:
Empty set (0.00 sec)
8. Aim: Display the total number of students in the table.
QUERY:
mysql> SELECT COUNT(*) FROM Student;
OUTPUT:
OUTPUT:
11. Aim: To display name, first 4 letters of the name and city in capital
letters.
QUERY:
mysql> SELECT Name,LEFT(Name,4),UPPER(City)
FROM Student;
13. Aim: To display name, month name and year from DOB.
QUERY:
mysql> SELECT Name,monthname(DOB),year(DOB)
FROM Student;
OUTPUT:
OUTPUT:
Query OK, 0 rows affected, 1 warning (0.42 sec)
Query OK, 1 row affected (0.12 sec)
Query OK, 1 row affected (0.05 sec)
Query OK, 1 row affected (0.11 sec)
14. Aim: To display highest mark wise department number.
QUERY:
mysql> SELECT Deptno,MAX(Marks)
FROM Student GROUP BY Deptno;
OUTPUT:
OUTPUT:
2. Aim: To display details of both tables using equijoin.
QUERY:
mysql> SELECT * FROM Student S,Dept D
WHERE S.Deptno = D.Deptno;
OUTPUT:
OUTPUT:
Empty set (0.03 sec)
5. Aim: To display student name, DOB, marks, and department name of
commerce students.
QUERY:
mysql> SELECT S.Name,S.DOB,S.Marks,D.Dname
FROM Student S,Dept D
WHERE S.Deptno=D.Deptno
AND D.Dname='Commerce';
6. Aim: To display student name, gender, city and department name whose
name starts with ‘S’.
QUERY:
mysql> SELECT S.Name,S.Gender,S.City,D.Dname
FROM Student S,Dept D
WHERE S.Deptno=D.Deptno
AND S.Name LIKE 'S%';
OUTPUT:
OUTPUT:
7. Aim: To display name, city, department name, incharge whose marks
are greater than 450.
QUERY:
mysql> SELECT S.Name,S.City,D.Dname,D.Incharge
FROM Student S,Dept D
WHERE S.Deptno=D.Deptno
AND S.Marks>450;