0% found this document useful (0 votes)
75 views9 pages

Ip - Class Xii - Comprehensive Assignment Mid Term 2022-2023

The document provides information about Pandas DataFrames and Series. It includes sample DataFrames and questions to work with them. Some key points: - It discusses changing row indices and column names of a DataFrame. - Importing COVID case data from a CSV file into a DataFrame and filtering for states with death counts over 10. - Importing student data from a CSV and filtering for a specific optional subject. - Questions on indexing, selecting, and filtering rows and columns from DataFrames. - Questions on bitwise logical operators and operations on DataFrames. - Information and questions on Pandas Series like creating, indexing, and operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views9 pages

Ip - Class Xii - Comprehensive Assignment Mid Term 2022-2023

The document provides information about Pandas DataFrames and Series. It includes sample DataFrames and questions to work with them. Some key points: - It discusses changing row indices and column names of a DataFrame. - Importing COVID case data from a CSV file into a DataFrame and filtering for states with death counts over 10. - Importing student data from a CSV and filtering for a specific optional subject. - Questions on indexing, selecting, and filtering rows and columns from DataFrames. - Questions on bitwise logical operators and operations on DataFrames. - Information and questions on Pandas Series like creating, indexing, and operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SACRED HEART SR. SEC. SCHOOL, B.R.S. NAGAR, LUDHIANA.

COMPREHENSIVE ASSIGNMENT – AUGUST 2022


INFORMATICS PRACTICES – CLASS XII

PANDAS DATAFRAMES
I.
Considering the dataframe DF
BID BNAME TYPE
0 221 The Firm Thriller
1 312 Tangled Rom-com

Write the statement to carry out changes in the row indices to roman numerals for DF
dataframe and column names to BOOKNO, NAME and GENRE within the dataframe.
II. PROGRAMS
1.
States total_cases Total_deaths Total_recovered
Punjab 167 11 10
Delhi 1510 27 24
Andhra Pradesh 432 7 11
Haryana 185 3 29
Kerala 379 2 179
Maharashtra 2334 149 217
Madhya Pradesh 604 36 0
Tamil Nadu 1173 11 50

Considering a file covid.csv, Import the data from this file into a dataframe named ‘Covid’. Then
create a new dataframe which contains only those states’ data where the death count is more
than 10. Write the newly created dataframe in a text file by the name ‘HighToll.txt’. The file
should contain the row numbers from 1 to N and the column labels should be included.
2. Import data into a dataframe from Student.CSV file containing Student Rollno, Name, Stream,
Optional Subject. The program should display data of all students who have opted for a specific
optional subject. The subject should be accepted from the user. The name of the column is
‘OPT’

III. INDEXING
Answer the questions based on the following DataFrame – books

BID BNAME BAUTHOR PRICE TYPE DOP


213 Digital fortress Dan Brown 356 Thriller 1999-12-12
441 Harry Potter J.K.Rowlings 750 Children 2001-09-23
524 Informatics Practices Sumita Arora 299 TextBook 2011-11-25
221 The Firm John Grisham 250 Thriller 1995-01-01
124 Bridget Jones Diary Helen Fielding 289 Rom-com 2000-12-12
312 Tangled Emma Chase 375 Rom-com 2005-05-09
123 Rainmaker John Grisham 325 Thriller 2001-10-21
1. Write statements to display the following outputs:

a)
BID BNAME TYPE
3 221 The Firm Thriller
5 312 Tangled Rom-com
6 123 Rainmaker Thriller

b) ‘Helen Fielding’
c)
BNAME BAUTHOR DOP
0 Digital Fortress Dan Brown 1999-12-12
1 Harry Potter J.K.Rowlings 2001-09-23
2 Informatics Practices Sumita Arora 2011-11-25
d)
BID BNAME BAUTHOR PRICE TYPE DOP
5 312 Tangled Emma Chase 375 Rom-com 2005-05-09
6 123 Rainmaker John Grisham 325 Thriller 2001-10-21
e)
BID 221
BNAME The Firm
BAUTHOR John Grisham
PRICE 250
TYPE Thriller
DOP 1995-01-01

f)
BNAME TYPE DOP
0 Digital fortress Thriller 1999-12-12
1 Harry Potter Children 2001-09-23
2 Informatics Practices TextBook 2011-11-25
3 The Firm Thriller 1995-01-01
4 Bridget Jones Diary Rom-com 2000-12-12
5 Tangled Rom-com 2005-05-09
6 Rainmaker Thriller 2001-10-21

2. Write the output of the given questions based on the following dataframe : friends
a) print(friends[[Name’,’Age’]])
b) print(friends.iloc[2:5,[1,3,4]])
c) print(friends.loc[1:2])
d) print(friends.iloc[1:2])
e) print(friends.loc[0:7:2])
f) print(friends.iloc[0:7:2])
g) print(friends.loc[7])
h) print(friends.iloc[2,[0,3,4]])
i) print(friends.loc[1:7:3, [‘Name’,’City’,’Email_id’]])
j) print(friends.Iloc[1:7:3, [0,2,4]])
k) print(friends.loc[6: , [‘Name’:’City’]])
l) print(friends[5])

IV. Write single statement for each of the the following:


1. Remove odd number of rows from a dataframe ‘Cars’ having rows from 0 to 7.
2. Add a new column Bonus in a dataframe Sales_Report which will store 12% of the values in
column Total_Sales.
3. Remove columns numbered 4 to 7 from a dataframe DF.
4. Carry out in place removal of column named ‘Filename’ from a dataframe ‘Files’
5. Add a new row no. 10 in dataframe ‘Numbers’ with values between 1 to 20.

V. a) Give the symbols for bitwise logical operators.


c) Why are multiple conditions used with bitwise and/or supposed to be
enclosed within brackets?
d) Write a statement to set the row indices of dataframe DF as first 3 rows
as true and next 2 to false.
e) Write a statement to display only the rows with true indices from a
dataframe DF.
f) Write a statement to display first, third and fourth row from dataframe
DF having 5 rows.
VI. Considering the following dataframe DF, write the statements for a) to d) and output for e) and f)

Pcode PName Salary Perks TeamName


0 1001 Abdul Ahmad 180000 78000 Mumbai
1 1002 Ravi Chandra 185000 75000 Kolkata
2 1003 John Ken 175000 81000 New Delhi
3 1005 Nazar Ameen 170000 62000 Mumbai
4 1008 Priyam Sen 190000 67000 Jaipur
5 1009 Rahul Mehra 189000 60000 Kolkata
a) To display rows where the salary is more than 180000.
b) To display rows where the Teamname is not Mumbai
c) To display rows where either Perks are more than 75000 or team is Kolkata.
d) To display the rows where Pcode is an odd number.
e) print(DF[‘TeamName’]== ‘Mumbai’)
f) print((DF[‘TeamName’]== ‘Mumbai’) | (DF[‘TeamName’]== ‘Kolkata’))

PANDA SERIES
1. To create an empty series object the, the Series() function is used with _________________.
2. Missing data values in Panda Series are filled with a _______________ value.
3. Pandas word is derived from ____________________________.
4. The command to install pandas is ____________________________________.
5. __________________ function is used to display ‘n’ no. of rows from the end of the series.
6. The most commonly used pandas data structure is ______________________.
7. ______________________ is the collection of values and the operations that can be performed on them.
8. The size of Pandas series is ________________.
9. __________________ parameter is used to provide the data set values to the series.
10. ______________ attribute of series object is used to access the data in the series with the help of index
names.
11. ________________ attribute will return False if all the values in the series are missing.
12. ________________ is the process of performing an operation of each element of the series.

13. Write Python code to do the following:


a) Create a series with the help of the following predefined dictionary having following values:
Key Value
101 ‘New York’
102 ‘California’
103 ‘Florida’
b) Create an empty series.
c) Create a series of 12 randomly generated numbers between 0 and 1 and the labelling of the
index should be month names from Jan to Dec.
d) Create a series with the 1/3 of each value of an array having values from 1 to 100.
e) Create a series of with elements as [1,2,3,4,5] and index labels accepted from the user.
14. What will be the output of the following codes?
a) Stream = [‘NM’,’Med’,’Commerce’,’Hum’]
S = pandas.Series(index = Stream, data = [154,23,132,15])
P=S
P[1] = 120
print(S)
P = S.copy()
P[3] = 12
print(S)
b) S = pandas.Series(data = [x for x in ‘abcdefghij’], index = range(1,11))
print(S[5:])
print(S[:-5])
print(S[-5:-9:-2])
print(S.loc[1:4])
print(S.loc[:7])
print(S.iloc[8:9])
S=S.drop(3)
print(S)
print(S.head(5))
c) S = pandas.Series([100,200,300,400,500], index = [‘A’,’B’,’C’,’D’,’E’])
P = pandas.Series([1,2,3,4,5], index = [‘A’,’B’,’C’,’D’,’E’])
C = pandas.Series([1,2,3,4,5])
D = pandas.Series([1,2,3])
print(S+P)
print(S/C)
print(D*C)
print(P.index)
print(C.index)
print((S+C).size)
print(P.nbytes)
print((D*C).hasnans)
15. Find the error(s) in the following code and write the correct code with each correction underlined.
Import pandas as pd
import numpy as np
a = numpy.linspace(1,100)
b = pd.series(index = range(1,100), a)
c = pd.series([1,2,3,4], index = range(1,6))
16. What will be the output of the following, considering a series object S has the given data?
0 NaN
1 0.78789
2 -0.54556
3 1.29292
4 -1.20202

a) print(S*100)
b) print(S>0)
SQL FUNCTIONS
Consider a table Student with following attributes: - Sname, DOB, Gender, Class,
Section, Percentage
1. Display the details of all boys who were born in year 2006 or 2007.
2. Display the first four letters of the names of class XII students.
3. Display the details of the students who have string ‘Sa’ in their names.
4. Display the total number of characters in the names of the students.
5. Display a report for each student were born in the following format:
Reema Sharma was born on Wednesday in the month of January.
6. Display the location of the first occurrence of character ‘A’ in the names of the students.
7. Considering the value 20191.968, display it in the following format:
20100 , 20191.9, 20191.97
8. Display the average percentage of girls of section B and C separately born in year 2005

CLASS XI SYLLABUS
I. Write the SQL statement to create the following STUDENT table. (2)
Field name Data type Size Constraint
S_Name Varchar 20
S_rollno Int 5 Primary Key
Marks Decimal 5,2
Grade Char 1
II. Considering the following table ITEM, write SQL statements for the following: (18)
ITEM
ICODE INAME MATERIAL PRICE ORD_DATE GRADE QTY
A191 TROUSERS COTTON 1000 2016-01-21 A 45
A109 HALF SLEEVE SHIRT SILK 1150 2016-08-12 C 123
A107 T- SHIRT POLYESTER 800 2015-11-23 B 50
A198 FULL SLEEVE SHIRT COTTON 950 2016-10-09 C 55
A924 COAT WOOLLEN 4000 2017-01-01 A 15
A123 SCARF SILK 1200 2015-10-12 B 20
A342 JEANS DENIM NULL 2016-09-12 A 34
A987 JACKET NULL 2500 2017-01-09 B 45
1) Display the details of the items where the word shirt occurs in the item name.
2) Display the different types of material in the table.
3) Display the code, name and price of those items whose order date was in the month of
October, 2015.
4) Find the highest quantity for cotton material items.
5) Display a list of items that are of cotton, silk or polyester material.
6) Add a new row in the table. Assume data on your own
7) Find the total value of each item in the table according to the price and quantity.
8) Display the code, name and price of the items in descending order of price.
9) Display the total number of items having grade as ‘B’ and ‘C’
10) Display the average price of cotton material items.
11) Add a new row but with values only for icode, iname and price.
12) Increase the price of all items ordered in the month of October by 5%.
13) Remove the rows from the table where quantity is in the range of 20 to 40.
14) Display the details of items where price has not been entered.
15) Display the details of items that have N as the second last character in the item name.
16) Display the item name , price in descending order of price within ascending order of name.
17) Display the total number of grades given to items in the table.
18) Display double of the price with heading as “Double price” for all items in the table.

III. Write the output of the following SQL queries based on the ITEM table as given above.
(Consider only the data given in the table for outputs)
1) Select price from item where ord_date > ‘2017-01-01’ or grade = ‘B’;
2) Select distinct grade from item;
3) Select avg(price) from item;
4) Select count(distinct material) from Item;
5) Select icode, iname, grade from item where iname like ‘%s’;
6) Select Count(price), Count(*) from Item;
7) What is the cardinality and degree of item table as given above?
8) Select grade, price, iname from item order by grade, iname desc;

IV. Differentiate between the following:


1) Candidate Key and Alternate Key
2) Tuple and Attribute

V. Write commands for the following:


1. Display the structure of the table Student.
2. Assuming that the table Student has no data, change the datatype of R_no and Admno
columns in the table from varchar to integer.
3. Remove the table student.

VI. Write the SQL commands on the basis of table ITEMS that has following table structure
Itemcode – int, Item_Name- Varchar, Item_desc - Varchar, Price – decimal, Qty – int

1. Write a query to make columns Itemcode and Item_name primary key.


2. Add two more columns Item_manufacturer( name of the manufacturing company) and
Ord_Date(date for ordering Item) in the table.
3. Remove constraint Not Null that was previously set for Price.
4. Display the constraints that have been set for the table.
5. Write a query to remove the primary key constraint in the table.
6. Increase the size of the column Qty to 5.
7. Remove the columns Item_manufacturer and ord_date from the table.
GROUP BY AND HAVING CLAUSE
Write SQL queries based on the following tables

1. Write a Query to display maximum salary paid in each department in descending order of
maximum salary.
2. Write a Query to Display the Highest and Lowest salary of the employees.
3. Write a Query to Display the total salary of the employees with each manager number where
manager number is more than 7800.
4. Write a Query to Display the Sum, Average, Highest and Lowest salary of the employees who
were hired after 2000 in each job type.
5. Write a query to display the number of employees with same job but only for the jobs other
than President.
6. Write a query to display the Highest and lowest salary of each department whose maximum
salary is more than 3000.
7. Display the difference between highest and lowest salary of salesman and managers.
8. Display the Total Annual Salary paid to the employees but only for those employees whose
monthly salary is more than 1500 for department no. 10 and 20 separately.
9. Display the employee name, job type and commission earned for employees of department
number 10 and 20.
10. Display the total no. of employees hired in each year.

11. Write the output of the following queries


a) Select count(*), deptno from emp where sal>1500 group by deptno;
b) Select ename, job from emp group by job;
c) Select Avg(comm) from emp;
d) Select mgr, Sum(Sal+comm) from emp group by mgr having mgr between 7600 and 7800;
e) Select max(sal), year(hiredate) from emp group by year(hiredate);

II. Study the following tables STAFF and answer the queries given below:
ID NAME DEPT POST EXPERIENCE GENDER
101 SIDHARTH SALES TRAINEE 12 M
104 RAGHAV FINANCE EXECUTIVE 5 M
107 NAMAN RESEARCH EXECUTIVE 3 M
114 NUPUR SALES MANAGER 9 F
109 JANVI FINANCE DIRECTOR 10 F
105 RAMA RESEARCH TRAINEE 3 F
117 JAMES SALES MANAGER 12 M
111 BINOY FINANCE EXECUTIVE 15 M
130 SAMUEL SALES DIRECTOR 10 M
1) Display the total no. of employees.
2) Find total no. of employees who have experience more than or equal to 10 employed at different
posts.
3) Display the lowest experience of employees in each department except finance.
4) Display the names of the staff members who are in sales department having more than 10 years of
experience.
5) Count the total number of male and female staff members.
6) Display the minimum allowance of female staff.
7) Display a list of all male staff members who are executives.
8) Display the list of members who are working in sales and research departments.
9) Display the list of directors with names starting with S.
10) Find the total number of staff members in each department.
11) Find the average experience of all the staff members in each department.
12) How many posts exist in the organization?
13) Write the output of the following:
i) SELECT DISTINCT POST FROM STAFF;
ii) SELECT COUNT(*) FROM STAFF WHERE GENDER = ‘F’;
iii) SELECT AVG(EXPERIENCE), POST FROM STAFF WHERE ID >105 GROUP BY POST
HAVING POST IN (‘MANAGER’, ‘DIRECTOR’) ORDER BY AVG(EXPERIENCE) DESC;
iv) SELECT COUNT(*), GENDER FROM STAFF WHERE POST NOT IN (‘MANAGER’, ‘TRAINEE’)
GROUP BY GENDER;

DATA VISUALIZATION
1. Using Python Matplotlib which graph is used to count how many values fall into each interval.
2. Which chart is best suited to represent categorical data?
3. Considering the given code, which of the following statements would display the given chart?
a = [1,2,3,4,5,6]
VI = [23,45,12,26,29,20]
VII = [21,34,22,34,19,27]

A) plt.plot(a,VI, VII, '--g', 'b')


B) plt.plot(a,VI, VII)
C) plt.plot(a,VI,'--g', a, VII, 'b')
D) plt.plot(a,VI,'b', a, VII, '--g')

4. tick_label is a parameter of which function?


5. Statement 1 – Labels of x-axis and y-axis are displayed by using label argument in plot() function.
Statement 2- legend() function can also be used to display the label text for data sets of the
chart
without using label argument of plot() function.
A) Both statement 1 and 2 are true
B) Both statement 1 and 2 are False
C) Statement 1 is true and Statement 2 is false
D) Statement 1 is false and Statement 2 is true
6. Write the statement to create 6 charts in the same figure in the following form.

7. What is the error in the following statements?


Plt.xticks([‘A’,’B’,’C’]) # to display tick labels for x-axis as A,B and C
Plt.legend(‘XI’,’XII’) # to set the labels for data sets in grouped bar chart as XI and XII
8. Fill in the missing statements of the following code.
Import matplotlib.pyplot as plt
A = [39,26,41
B = [22,55,25]
_____________ # to represent A and B datasets in a line chart
_____________ # to display ‘Classes’ as text for x-axis
_____________ # to display ‘Marks’ as text for y-axis
_____________ # to display ‘X’,’XI’,’XII’ as tick labels of x-axis
_____________# to display A and B as labels for two data sets.
_____________ # to display the figure
9. Which argument sets the thickness of the bar in horizontal bar chart?
10. Which argument is used to display horizontal histogram?
11. Name the argument of dataframe.plot() function that decides which plot is to be displayed.
12. What is the purpose of fontdict argument? Write a statement to display title of a plot using any
set of values for fontdict argument.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy