Please refer to Python Pandas II-DataFrames and Other Operations Class 11 Informatics Practices Exam Questions provided below. These questions and answers for Class 11 Informatics Practices have been designed based on the past trend of questions and important topics in your class 11 Informatics Practices books. You should go through all Class 11 Informatics Practices Important Questions provided by our teachers which will help you to get more marks in upcoming exams.
Class 11 Informatics Practices Exam Questions Python Pandas II-DataFrames and Other Operations
Class 11 Informatics Practices students should read and understand the important questions and answers provided below for Python Pandas II-DataFrames and Other Operations which will help them to understand all important and difficult topics.
Short Answer Type Questions
Q.1 How does dataframe object specify indexes to its data rows?
Ans-It has two indexes- a roe index(axis=0) and a column index(axis=1)
Q.2 Write code statements to list the following, from a dataframe namely sales.
(a) List only columns „item‟ and „Revenue‟.
(b) List rows from 3 to 7.
(c) List the value of cell in 5th row and, „item‟ column.
Ans- (a) sales.loc [„item‟, ‟Revenue‟]
(c ) sales.item
Q.3 How would you add a new column namely „val‟ to a dataframe df that has 10 rows in it and has columns as „Item‟, ‟Qty‟, ‟Price‟? you can choose to put any values of your choice.
Q.4 Write code to print information about a series object.
Q.5 Write code to get summary details about a dataframe object for all its columns including numeric and string columns.
Q.6 The head() and tail() extract rows or columns from a dataframe. Explain.
Ans- head() and tail() functions retrieve 5 top and 5 bottom rows respectively of a DataFrame object. The number of rows to be displayed can be changed by specifying a number as parameter. For ex-
Df.head() // will display top 5 rows
Df.tail() // will display bottom 5 rows
Df.head(3) // will display top 3 rows
Df.tail(7) // will display bottom 7 rows
Q.7 Why does Python change the datatype of a column as soon as it stores an empty value (NaN) even though it has all over values stored as integer?
Ans- Because in Python, integer types cannot store NaN values.
Q.8 What is a DataFrame object? How it is created in Python?
Ans- A DataFrame object is a two-dimensional labeled array which is actually an ordered collection of columns where columns may store different types of data.
A dataFrame object can be created by following ways-
- From a 2-D Dictionary
- From a 2-D ndarray
- From a 2-D Dictionary with values as Series object
- From an another DataFrame object
Skill Based Questions
Q.1 Given a dataframe df as shown bellow
What will be the result of the following code segment.
(a) df[„c‟] = np.NaN (b) df[„c‟] = [2,5] (c) df[„c‟] = [12,15,27]
(b) Will raise an error -Length of values does not match length of index
Q.2 Write code statements for a dataframe df for the following –
(a) Delete an existing column from it.
(b) Delete rows from 3 to 6 from it.
(c) Check if the dataframe has any missing values.
(d) fill all missing values with 999 in it.
Ans: (a) del df
(b ) df.drop([3,4,5,6])
(c ) df.isnull()
Ans: Because both the dataframes are differently labeled.
It should be-
Q.8 Four series objects Temp1, Temp2, Temp3 and Temp4 store the temperature of week1, week2, week3 and week4 respectively. Create a dataframe from these four series objects where the indexes should be „Sunday‟, „Monday‟, „Tuesday‟ . . . „Saturday‟, and columns should be „Week1‟, ‟Week2‟, ‟Week3‟ and ‟Week4‟.
Q.9 From the dataframe object created in previous question, write a script to calculate –
(a) Average temperature for each day of the week i.e. average temperatures for Mondays, Tuesdays and so on.
(b) Average temperature per week.
(c) Average temperature of whole month.
Q.10 Given a dataframe that stores the details of past 5 years‟ monthly sales. Some old data is missing. Write a script to calculate average:
->Monthly sales across the year -> Yearly sales.
Make sure that missing values do not hamper the overall result.
We hope you liked the above provided Python Pandas II-DataFrames and Other Operations Class 11 Informatics Practices Exam Questions. If you have any further questions please put them in the comments section below so that our teachers can provide you an answer.