You are on page 1of 36

2023 - 2 4

PRACTICAL FILE
INFORMATICS PRACTICES

SUBMITTED BY: ASHLY GEORGE


GRADE: 12 SECTION: B
QUESTION 1:
Write a program to create a pandas series from a dictionary of values and a ndarry.

INPUT OUTPUT
QUESTION 2:
Write a program to multiply and divide two Pandas Series.

INPUT OUTPUT
QUESTION 3:
Write a program to multiply and divide two Pandas Series.

INPUT OUTPUT
QUESTION 4:
Write a program to create a Series named S1 and display its type. Change the
Series into a list and display its type. Also display the elements of the Series which
are above 20.

INPUT OUTPUT
QUESTION 5:
Write a program to change the order of index of a given series.
Original Data Series:

Data Series after changing the order of index:

INPUT OUTPUT
QUESTION 6:
Write a program to create and display a DataFrame from a specified dictionary
with index labels.
.

INPUT OUTPUT
QUESTION 7:
Write a program to get the first 3 rows and last 4 rows of a given DataFrame

INPUT OUTPUT
QUESTION 8:
Create a dataframe for examination result and display row labels, column labels,
data types of each column and the dimensions

INPUT OUTPUT
QUESTION 9:
Write a program to create a Dataframe quarterly sales where each row contains
the item category, item name, and expenditure.
Do the following tasks in the dataframe:
a) Display the itemname and expenditure columns
b) Display the rows where expenditure is more than 2500

INPUT OUTPUT
QUESTION 10:
Write a program to create a dataframe ‘data’ with the following details:

Write code to display the following:

a) Display city and favourite_color columns of first, fourth and seventh rows
b) Access value Chennai
c) Find rows where value of age is more than 16
d) Find rows where age is more than 13 and gender is Female

INPUT OUTPUT
QUESTION 11:
Write a Pandas program to count the number of rows and columns of a
DataFrame.

INPUT OUTPUT
QUESTION 12:
Write a program to:
a) import data from CSV to Pandas
b) export data from Pandas to a CSV file

INPUT OUTPUT
QUESTION 13:
Write a Program to create a dataframe emp to hold empno, empname and salary
details of 5 employees and perform the following tasks:
(a) Add a column ‘Bonus’ which is calculated as 5% of salary.
(b) Add a column ‘Dept’ between empname and salary columns and
populate it
with appropriate values.
(c) Remove the column ‘Bonus’.

INPUT OUTPUT
QUESTION 14:
Write a program to create dataframe ‘stock’ with the following data:

Write suitable python statements for the following:


i. Add a column called Num_Copies with the following data:
[300,290,450,760].
ii. Add a new genre of type ‘Folk Tale' having code as “FT” and
600 number of copies.
iii. Rename the column ‘Code’ to ‘Book_Code’

INPUT OUTPUT
QUESTION 15:
Write a program to select the 'name' and 'score' columns from the following
DataFrame. Also change the score in row ‘d’ to 11.5.

INPUT OUTPUT
QUESTION 16:
A DataFrame 'item' has the following columns : pid,pname, price.

Write python statements for the following:


(a) Add a new column ‘qty’ with values 10,65,45,80

(b) Delete column price

(c) Delete the second row in the Dataframe

(d) Rename column qty to quantity

OUTPUT
INPUT
DATA
VISUALISATION
QUESTION 17:
Write a program to create a dataframe to store the school result data, analyses the
performance of the students on different parameters, e.g., subject wise or class
wise.

INPUT OUTPUT
QUESTION 18:
Given a dataframe df1 as shown below:

Write code to create,


(a) A line chart from the 1990 and 2000 columns of dataframe df1
(b) Create a bar chart plotting the three columns of dataframe df1

INPUT OUTPUT
QUESTION 19:
Create a Dataframe quarterly_sales with columns Salesman, Sales, Quarter and
District.
Write a program to draw a histogram based on monthly sales report for all
numeric columns

INPUT OUTPUT
QUESTION 20:
Consider the data given below:

Using the above data, plot the following:


(a) A line chart depicting the prices of the apps
(b) A bar chart depicting the downloads of the apps
(c) Compute Estdownload sequence that has each download value divided
by 1000. Now create a bar chart that plots multiple bar for prices as
well as Estdownloads
(d) The charts should have proper titles for the charts, axes, legends etc.

INPUT OUTPUT
QUESTION 21:
a) Create a database school. Inside this database, create a table student with
the appropriate specifications for storing the following data.

CREATE DATABASE SCHOOL;

SHOW DATABASES;

CREATE TABLE STUDENT (No INT, Name VARCHAR(25), Stipend DECIMAL, Stream
VARCHAR(30), AvgMark DECIMAL, Grade VARCHAR(5), Class VARCHAR(10), PRIMARY
KEY(No));

b) Populate the table with the following records

INSERT INTO student

-> VALUES(1, 'Karan', 400.00, 'Medical', 78.5, 'B', '12B');

INSERT INTO student

-> VALUES(2, 'Divakar', 450.00, 'Commerce', 89.2, 'A', '11C');

INSERT INTO student

-> VALUES(3, 'Divya', 300.00, 'Commerce', 68.6, 'C', '12C');

INSERT INTO student

-> VALUES(4, 'Arun', 350.00, 'Humanities', 73.1, 'B', '12C');

INSERT INTO student

-> VALUES(5, 'Sabina', 500.00, 'Nonmedical', 90.6, 'A', '11A' );

INSERT INTO student

-> VALUES(6, 'John', 400.00, 'Medical', 75.4, 'B', '12B');


INSERT INTO student

-> VALUES(7, 'Robert' , 250.00, 'Humanites', 64.4, 'C', '11A');

INSERT INTO student

-> VALUES(8, 'Rubina', 450.00, 'Nonmedical', 88.5, 'A', '12A');

INSERT INTO student

-> VALUES(9, 'Vikas', 500.00, 'Nonmedical', 92.0, 'A', '12A');

INSERT INTO student

-> VALUES(10, 'Mohan', 300.00, 'Commerce', 67.5, 'C', '12C');

c) Delete the details of ‘Mohan’. Undo the changes. Save the details
permanently.
delete from student where Name = 'Mohan';

select * from student;


d) Delete the details of ‘Mohan’. Undo the changes. Save the details
permanently.

SELECT * FROM student WHERE Stream = 'Nonmedical';

e) List the names of those students who are in class 12 sorted by stipend

SELECT Name FROM student

-> WHERE Class LIKE '12%'

-> ORDER BY Stipend;

f) List all students sorted by AvgMarks in descending order

SELECT * FROM student

-> ORDER BY AvgMark DESC;


g) Display the average stipend of each stream

SELECT AvgMark, Stipend,


Stream FROM student;

h) Display the details of students who scored Avgmarks less than 75 and Grade
is B

SELECT * FROM student WHERE AvgMark < 75 AND Grade = 'B';

i) Display the details of students who scored Avgmarks less than 75 and
Grade is B

SELECT SUM(Stipend) FROM student;

j) List the name and stream of students whose name contains letter ‘a’

SELECT Name, Stream FROM student WHERE Name LIKE '%a%';


k) List the details of students whose grade is either A or C
SELECT * FROM student WHERE Grade IN ('B', 'C');

l) Display No, Name and Class of students whose score is in the range 60 to 80
SELECT No, Name, Class FROM student WHERE AvgMark BETWEEN 60 AND 80;

m) Display the different streams in the table


SELECT DISTINCT Stream FROM student;

n) Display the number of students in each stream


SELECT Stream, COUNT(Stream) as number_of_students FROM student GROUP
BY Stream;
o) List the details of students who are not in the Humanities stream
SELECT * FROM student WHERE Stream != 'Humanities';
QUESTION 22:
a) Create a database school. Inside this database, create a table student
with the appropriate specifications for storing the following data.

USE school;

CREATE TABLE Teacher

-> (ID INT PRIMARY KEY,

-> Name VARCHAR(30),

-> Department VARCHAR(30),

-> Hiredate DATE,

-> Category VARCHAR(5),

-> Gender VARCHAR(5),

-> Salary INT);

b) Insert the given records into the table

INSERT INTO Teacher

-> VALUES(1, 'Tanya Nanda', 'Social Studies', '1994-03-17', 'TGT', 'F', 25000);

INSERT INTO Teacher

-> VALUES(2, 'Saurabh Sharma', 'Art', '1990-02-12', 'PRT', 'M', 20000);

INSERT INTO Teacher

-> VALUES(3, 'Nandita Arora', 'English', '1980-05-16', 'PGT', 'F', 30000);

INSERT INTO Teacher

-> VALUES(4, 'James Jacob', 'English', '1989-10-16', 'TGT', 'M', 25000);

INSERT INTO Teacher

-> VALUES(5, 'Jaspreet Kaur', 'Hindi', '1990-08-01', 'PRT', 'F', 22000);

INSERT INTO Teacher

-> VALUES(6, 'Disha Sehgal', 'Math', '1980-03-17', 'PRT', 'F', 21000);


INSERT INTO Teacher

-> VALUES(7, 'Siddharth Kapoor', 'Science', '1994-09-02', 'TGT', 'M', 27000);

INSERT INTO Teacher

-> VALUES(8, 'Sonali Mukerjee', 'Math', '1980-11-17', 'TGT', 'F', 24500);


c) Display all information about teachers of PGT category
SELECT * FROM Teacher WHERE Category = 'PGT';

d) To list the names of female teachers of Hindi Department


SELECT Name FROM Teacher WHERE Department = 'Hindi'
AND Gender = F';

e) To list names, departments and date of hiring of all teachers in ascending order of date of
hiring
SELECT Name, Department, Hiredate FROM Teacher

-> ORDER BY Hiredate;

f) To count the number of teachers in English department

SELECT Department, COUNT(Department) as number_of_teachers FROM Teacher

-> WHERE Department = 'English';


g) To list the teachers details whose name starts with letter ‘s’
SELECT * FROM
SELECT Teacher
* FROM Teacher

-> WHERE Name LIKE 'S%';

-> WHERE Name LIKE


'S%';

h) Display gender wise average salaries


SELECT * FROM
SELECT Teacher
Gender, AVG(Salary) as average_salary

-> FROM Teacher

-> GROUP BY Gender;

-> WHERE Name LIKE


'S%';

i) Display total salary of each category


SELECT * FROM
SELECT Teacher
Department, SUM(Salary) as deptwise_total_salary

-> FROM Teacher

-> GROUP BY Department;

-> WHERE Name LIKE


'S%';

j) To list the details of teachers who joined in year 1980


SELECT * FROM Teacher
SELECT * FROM Teacher WHERE Hiredate LIKE '1980%';

-> WHERE Name LIKE


'S%';
k) Display the name, department and category of teachers whose
salary is less than 23000
SELECT Name, Department, Category
SELECT * FROM Teacher
-> FROM Teacher

-> WHERE Salary <23000;

-> WHERE Name LIKE


'S%';

l) Add a new column Bonus to the table and Compute the Bonus as 10% of
Salary
ALTER TABLE Teacher

-> ADD BONUS DECIMAL;


UPDATE Teacher

-> SET BONUS = Salary * 10/100 ;

m) Add a new column Bonus to the table and Compute the Bonus as 10% of
Salary
SELECT Name, Department
-> FROM Teacher
#-> WHERE Name NOT LIKE '%r%';
n) A Display the details of teachers in ascending order of Category, then descending
order of Salary
SELECT * FROM Teacher ORDER BY Category ASC;

SELECT * FROM Teacher ORDER BY Salary DESC;

o) Display the details of teachers whose department is either Art or Science

SELECT * FROM Teacher WHERE Department IN('Art', 'Science');

You might also like