Lab Programs
Lab Programs
PRACTICES (065)
NAME :
STD :
PROGRAM CODE
INPUT
OUTPUT
PROGRAM 2
Write a Python program to create a series that stores the State name as index and it’sarea in Km2of
following south Indian states as values.
PROGRAM CODE
OUTPUT
PROGRAM 3
Write a Python program to accept the salary of 5 employees for the current month and store it in a
Series S1 with name of employee as the index and salary as value. Another Series S2 stores the
bonus earned by each employee. Calculate the net salary earned by each employee. Display the
details of employees who have a net salary of more than 35000.
PROGRAM CODE
INPUT
OUTPUT
PROGRAM 4
Write a Python program to create a series using lists to store the year and unemployment rate as
percentage for 6 years.
a) Calculate and display those years where unemployment rate is above 15 percentage.
b) Display the unemployment rate of year 2014 and 2015
c) Display the unemployment rate of year 2018 and 2019
d) Display the unemployment rate of year 2016 and 2017
e) Display the unemployment rate of year 2015 and 2018
Sample Data
PROGRAM CODE
INPUT
OUTPUT
PROGRAM 8
Write a Python program to create a DataFrame to accept and store Name , Accountancymarks
and IP marks(out of 100) for n students. Roll Number will be the row index. Also write the
code to :
PROGRAM CODE
INPUT
OUTPUT
PROGRAM 9
Create a Data frame to store the following salary details of employees in an
organization.
Employee Details -> Name, Basic, HRA
PROGRAM CODE
OUTPUT
PROGRAM 10
Given the DataFrame DF to store the project details of a software organisation.
PROGRAM CODE
OUTPUT
PROGRAM 11
Write a program to create a DataFrame state for storing the Literacy rate of 5 statesgiven below.
Use StNo data as row index.
StNo State Name 1981 1991 2001 2011
28 Andhra Pradesh 35.7 44.1 60.5 67.7
29 Karnataka 46.2 56.0 66.6 75.6
33 Tamil Nadu 54.4 62.7 73.5 80.3
27 Maharashtra 57.2 64.9 76.9 82.9
32 Kerala 78.9 89.8 90.9 93.9
Display the Dataframe and write code to perform the following :
a) Display the literacy rates in 2011
b) Display the literacy data of Tamil Nadu
c) Display the row labels of dataframe
d) Display the column labels of dataframe
PROGRAM CODE
OUTPUT
PROGRAM 12
Write a program to create a DataFrame state for storing the Literacy rate of 5 statesgiven below.
Use StNo data as row index.
StNo State Name 1981 1991 2001 2011
28 Andhra Pradesh 35.7 44.1 60.5 67.7
29 Karnataka 46.2 56.0 66.6 75.6
33 Tamil Nadu 54.4 62.7 73.5 80.3
27 Maharashtra 57.2 64.9 76.9 82.9
32 Kerala 78.9 89.8 90.9 93.9
Display the Dataframe and write code to perform the following :
a) Display the datatype of dataframe
b) Display the data type of each column in dataframe
c) Display the dimension of dataframe
d) Display the number of elements in the dataframe
PROGRAM CODE
OUTPUT
PROGRAM 13
Write a python program to
i) Accept the following employee details (EmployeeNo, Name, Salary) and store them in a
DataFrame df.
ii) Export the data from DataFrame and store it in a csv file(employee.csv).
iii) Read data from the csv file and display the content .
PROGRAM CODE
INPUT
OUTPUT
PROGRAM 14
Marks Grade
>=90 A
>=75 B
>=50 C
< 50 Referred
PROGRAM CODE
INPUT
OUTPUT
PROGRAM 15
The Unemployment rates of 6 years are stored in a series. Draw a line graph to displaythe data. Give
appropriate title and labels.
PROGRAM CODE
OUTPUT
PROGRAM 16
Create a DataFrame to store the IP marks secured by 5 students in Term1 Examinations in Term
2examinations. Perform the following operations on the Dataframes.
1. Create a column total marks to store total marks secured in both exams.
2. Display the details of students who have scored a total of more than 170.
3. Draw a line graph to display the total marks of student scored by each student.
Term 1 IP Term 2 IP
Name
Marks Marks
Athul 90 85
Divya 85 80
Irene 89 80
Karthik 80 80
Manya 95 90
PROGRAM CODE
OUTPUT
PROGRAM 17
The Marks scored by 5 students in 2 subjects(out of 100) and store it in a Dataframe. Analyse the
subject wise performance of students using a Line chart.
The average temperature(in Celsius) of seven days in a week is stored in a Series. Analyse
thetemperature variation using a Bar chart.
wday- Mon, Tue, Wed, Thu, Fri, Sat, Sun
avgtmp=34,32,30,34,29,31,33
PROGRAM CODE
OUTPUT
PROGRAM 19
Create a DataFrame to store the following Employees Code and Age of employees. Draw
Histogramsto perform a comparative analysis of this data.
ECode – 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
Age – 25,23,25,30,25,30,28,35,21,29,32,35,26,20,29
PROGRAM CODE
38
OUTPUT
39
‘TechIndia’ is a software development firm. Create a database TechIndia. In the
database create a table Employee with the given structure to store the details of its
employees. Enter the data given.
DATABASE : TechIndia
TABLE : Employee
Field Name Type Size Constraint
EmpID Char 4 Primary Key
EName Varchar 25 Not NULL
Gender Char 1 M or F
Dob Date
Department Char 4
Grade Char 2
Salary Integer 6
9. Display the Name, Gender and Date of birth of all employees earning salary less than
40000.
Select EName, Gender, Dob from Employee where Salary <40000;
10.Display the Name of employees as ‘Employee Name’ and Salary who earn salary
between 20000 and 35000.
Select EName ‘Employee Name’, Salary from Employee where Salary between
20000 and 35000;
Select EName ‘Employee Name’, Salary from Employee where Salary >=20000 and
Salary <= 35000;
12.Display the Name, gender and salary of employees in the descending order of their
salary
Select EName, Gender, Salary from Employee order by Salary desc;
13.Display the Name and Department of employees in the ascending of name within
department.
Select EName, Department from Employee order by Department, Name;
15.Display name and department of employees whose name has ‘u’ as second alphabet.
Select EName, Department from Employee where EName like ‘_u%’
41
Insert into Employee values (‘E111’, ‘Sangamitra’, ‘F’, ‘1997-08-26’, ‘HRD’, ‘E2’,
30000);
Create table Book(AccNo int(4) PRIMARY KEY, Bname varchar(30) NOT NULL,
Author varchar(30) NOT NULL, Price int(4), DOP date, Category char(1) check
(Category in ‘A’ ,’B’,’C’,’D’,’E’,’O’));
Describe Book;
Insert into Book values (2435, ‘Rich Dad Poor Dad’, ‘Robert T Kiyosaki’,
‘2007/02/15’, ‘B’);
42
MySQL – Single Row Functions
Exercise 1
Use XIIEIP;
Create table Book(AccNo int(4) PRIMARY KEY, Bname varchar(30) NOT NULL,
Author varchar(30) NOT NULL, Price int(4), DOP date, Category char(1) check
(Category in ‘A’ ,’B’,’C’,’D’,’E’,’O’));
Describe Book;
Insert into Book values (2435, ‘Rich Dad Poor Dad’, ‘Robert T Kiyosaki’,
‘2007/02/15’, ‘B’);
43
2. Display the name of book in capital letters and author’s name in small letter of
books which cost more than 300.
3. Display the number of characters in each book name along with book name for
book with accession number 2435,2478 and 2604.
4. Display the name of the book and the first letter of each book name belonging to
category A.
6. Display the 3rd, 4th and 5th character of each book name in category C.
44
7. Display the last 3 character of author name of book with accession number more
than 2600 in descending order of accession number.
8. Display the first and last alphabet of author’s name of author’s who have written
books with book name which contains word ‘of’
10.Display the names of books purchased in December along with their price.
45
11.Display the book details of books purchased in April 2006.
15.Display the name and date of purchase of books which are 14 years old.
46
16.Display the name and date of purchase of books purchased on 5th of a month.
17.Display the length of book names raised to the power of 2 for books in category
A, along with the book names.
18.Display the square root of accession number of books along with book name and
author whose author name is more than 25 characters long.
19.Display the month and year of purchase of book along with book name whose
price is not available.
47
20.Display the dayname and month of purchase of all books along with book name of
books which cost more than 300.
-------------------------
48
MySQL - Group Functions
Exercise 2.
‘TechIndia’ is a software development firm. Create a database TechIndia. In the
database create a table Employee with the given structure to store the details of its
employees. Enter the data given.
DATABASE : TechIndia
TABLE : Employee
Field Name Type Size Constraint
EmpID Char 4 Primary Key
EName Varchar 25 Not NULL
Gender Char 1 M or F
Dob Date
Department Char 4 Can take any one value - ACCT, HRD,
IT
Grade Char 2 Can take any one value -E1, E2, E3
Salary Integer 6
Use TechIndia;
Create table Employee ( EmpID char(4) PRIMARY KEY, EName varchar(25) NOT
NULL, Gender char(1) check (Gender ='M' or Gender='F'), Dob date, Department
char(4) check (Department in ('ACCT', 'HRD', 'IT')) , Grade char(2) check (grade in
('E1', 'E2','E3')), Salary int(5));
Describe Employee;
49
Write the SQL commands for the following :
1. Display the total number of Employees in the organisation.
4. Display the total number of Male and total number of Female staff working in the
organisation.
50
6. Display the total salary earned by Male and total salary earned by Female staff of IT
Department.
7. Display the total salary of those departments whose total salary is more than one
lakh.
9. Display the average salary earned by male and female employees within each
department.
11.Display the average salary of employees in each grade, if the average salary is more
than 30000.
51
12.Display the maximum salary earned by the employees.
52
16.Display the minimum salary earned by male employees and minimum salary earned
by female employees.
17.Display the total salary of employees in each grade, where the number of employees
in each grade is more than or equal to 5.
19. Display the number of female employees in HRD department who earn more than
35000.
-----------------------
53