0% found this document useful (0 votes)
17 views

Ip Practicals

Here is the code to display item name and expenditure from the data frame: import pandas as pd sales = {'Item category':[200, 201, 202], 'Item name':['Plate','Glass','Vessel'], 'expenditure':[80,35,500]} df = pd.DataFrame(sales) print(df[['Item name','expenditure']]) This code: 1. Creates a dictionary with sample data 2. Converts it to a dataframe 3. Prints the dataframe selecting only the 'Item name' and 'expenditure' columns Let me know if you have any other questions!

Uploaded by

aswinmadhav9a
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Ip Practicals

Here is the code to display item name and expenditure from the data frame: import pandas as pd sales = {'Item category':[200, 201, 202], 'Item name':['Plate','Glass','Vessel'], 'expenditure':[80,35,500]} df = pd.DataFrame(sales) print(df[['Item name','expenditure']]) This code: 1. Creates a dictionary with sample data 2. Converts it to a dataframe 3. Prints the dataframe selecting only the 'Item name' and 'expenditure' columns Let me know if you have any other questions!

Uploaded by

aswinmadhav9a
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 62

AMRITA VIDYALAYAM

PALAKKAD

SESSION:- 2023-24

INFORMATICS PRACTICES
SUB.CODE- 065
PRACTICAL FILE
NAME:_____________________________

CLASS: _______ STREAM:___________


REGISTER NO: _______________
CERTIFICATE

This is to certify that___________________________,


Roll No____________ of Class _________ Section _________
has prepared the Practical file as per the prescribed
practical syllabus of INFORMATICS PRACTICES (065) Class
XII (C.B.S.E.)
Under my supervision, I am completely satisfied by the
performance.

I wish him/her all the success in life.

Principal’s Internal Examiner’s External Examiner’s


Signature Signature Signature

___________ ____________ _____________


INDEX
PYTHON
Practical Program
S.No Date Pg.no Teacher’s
Name
Signature

1 Pandas series of dictionary

2 Data frame series from dictionary

3 Series with index using employee


details

4 Series with index employee detail


whose salary more than 18000

5 Data frame using dictionary of list

6 Data frame using dictionary of series

7 Data frame displays row label, column


label and data type of each column

8 Data frame sales where each row


contains detail of items and display
first to third row.

9 Data frame sales and show item


category, item name and cname.

10 Display Dataframe of name and


expenditure.

11 Display DataFrame of last two records.


12 Replace item name and expenditure of
jar to 150/- using data frame.

13 Display salary of employee and 200 as


bonus.

14 Display data frame, fill NaN values with


0.

Read csv file into data frame which


importing and exporting data between
15 pandas and CSV file.

Data visualization
Display line chart with suitable label.
16
Display line chart with suitable label
using marker, markeredgecolor, color
17 and label.

Display multiple bar chart of no. of


18 students in a class.

19 Display histogram of student’s height


and weight

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’

Ename Jeni Karan Priya Kamal Santha Vimal


Salary 24000 20000 18000 1800 17000 15000

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:

Aim: Create a series with index as emp-name and Salary as values.


Display the records of those whose salary is more than 18000.

Ename Jeni Karan Priya Kamal Santha Vimal


Salary 24000 20000 18000 1800 17000 15000

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));

2. Aim: Insert details of five students in the above table.


QUERY:
mysql>INSERT INTO Student VALUES (1,'Raj', 12, '2006-05-25',
'M', 'Mumbai', 101, 453);
mysql>INSERT INTO Student VALUES (2,'Diksha', 11, '2007-07-20',
'F','Kolkata', 102, 408);
mysql>INSERT INTO Student VALUES (3,'Akshay', 11, '2007-11-01',
'M','Banglore', 102, 489);
mysql>INSERT INTO Student VALUES (4,'Radika', 12, '2006-12-23',
'F','Chennai', 103, 397);
mysql> INSERT INTO Student VALUES (5,'Deep', 11, '2007-03-28',
'M','Kochi', 101, 373);
mysql> SELECT * FROM Student;
OUTPUT:
Query OK, 0 rows affected (0.39 sec)
Records: 0 Duplicates: 0 Warnings: 0

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;

4. Aim: Add a new column ‘Class’ in the above table.


QUERY:
mysql> ALTER TABLE Student
ADD Class INT(4);
mysql> SELECT * FROM Student;
OUTPUT:

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;

6. Aim: To display details of students whose marks is more than 400.


QUERY:
mysql> SELECT * FROM Student
WHERE Marks>400;

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;

9. Aim: To display name is ascending order.


QUERY:
mysql> SELECT Name FROM Student
ORDER BY Name;

10. Aim: To display details of students of class 11


QUERY:
mysql>SELECT * FROM Student
WHERE Class = 11;
OUTPUT:

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;

12. Aim: To display name 2nd character onwards 3 characters, Stno.


QUERY:
mysql> SELECT Name,SUBSTR(Name,2,3),Stno
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;

PRACTICAL NO.21: MySQL Joins

1. Aim: Create a table Dept with Deptno, Dname, Incharge.


QUERY:
mysql> CREATE TABLE Dept(Deptno INT(4), Dname VARCHAR(20),
InchargeVARCHAR(20));
mysql> INSERT INTO Dept VALUES(101,'Commerce','Harsh');
mysql> INSERT INTO Dept VALUES(102,'Science','Shivani');
mysql> INSERT INTO Dept VALUES(103,'Humanities','Krishna');
mysql> SELECT * FROM Dept;
OUTPUT:

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;

3. Aim: To display student name, department name and incharge whose


mark is between 400 and 490.
QUERY:
mysql> SELECT S.Name,D.Dname,D.Incharge FROM Student S,Dept D
WHERE S.Deptno = D.Deptno AND
S.Marks BETWEEN 400 AND 490;

4. Aim: To display name, DOB, department number, department name and


incharge whose department number is either 101 or 103.
QUERY:
mysql>SELECT S.Name,S.Deptno,S.DOB,D.Dname,D.Incharge
FROM Student S,Dept D
WHERE S.Deptno=D.Deptno
AND (S.Deptno = 101 OR S.Deptno = 103);

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;

8. Aim: To display name along with department name and marks.


QUERY:
mysql> SELECT S.Name,S.Marks,D.Dname
FROM Student S,Dept D
WHERE S.Deptno=D.Deptno;

You might also like