In this article, we are going to discuss some important Dataframe class 12 questions and answers. These questions are based on the topic select or access data from a dataframe. If you are a Class 12 Informatics Practices student then you landed on the right page. Here we go!

Important Dataframe class 12 questions and answers

The questions are divided into two parts. Objective type questions and Subjective type questions. So let’s begin this article Important Dataframe class 12 questions and answers with Objective type questions. 

Objective type Questions (OTQs) 

#1 Which of the following is the correct syntax to select or access columns from the dataframe using column names?

a) df(col1,col2,…,coln)

b) df[[col1,col2,…,coln]]

c) df[col1,col2,…,coln]

d) df{col1:col2:…,:coln}

#2 Ms. Kavitha wants to print a single column from the dataframe, which of the following is correct syntax for her?

a) df(col)

b) df<col>

c) df[col]

d) df{df:col}

#3 You cannot print columns using dot notation when the column name is having a space in the dataframe. (True/False)

#4 Observe the following dataframe code:

dt=({'Name':['Akshit','Bharat','Chetan','Dhaval','Gaurang'],
'InternalMarks':[18,19,20,18,19],
'AnnualExam':[76,78,80,76,73]})
df=pd.DataFrame(dt)

Which of the following code will print names and Annual marks of students?

a) print(df.loc[:,’Name’:’AnnualExam’])

b) print(df.loc[‘Name’:’AnnualExam’])

c) print(df.loc[:,df.columns!=’InternalMarks’])

d) All of these

#5 What will be the output of following code:

dt={'Name':['Akshit','Bharat','Chetan','Dhaval','Gaurang'],
'InternalMarks':[18,19,20,18,19],
'AnnualExam':[76,78,80,76,73]}
df=pd.DataFrame(dt)
print(df.iloc[0:2,0:2])

a)

   Name   InternalMarks
0 Akshit 18
1 Bharat 19

b)

   Name  AnnualExam
0 Akshit 76
1 Bharat 78
2 Chetan 80

c) 

   Name InternalMarks AnnualExam
0 Akshit 18 76
1 Bharat 19 78

d) 

Empty DataFrame
Columns: [Name, InternalMarks, AnnualExam]
Index: []

#6 You can also use slicing to display columns from the dataframe. (True/False)

#7 To display a specific value you can use ________ property along with dot notation. (Ans. at)

#8 For integer location you can use ______ property along with dot notation. (Ans. iat)

Now in the next section of important Dataframe class 12 questions and answers, we are going to discuss subjective type questions. 

Q – 1 What are the way to select or access data from a data frame?

Ans.: You can select or access data from a data frame in the following ways:

    1. Using column name(s)
    2. Using . (dot) notation
    3. Using loc[]
    4. Using iloc[]
    5. Using slicing
    6. Individual Value using at[] & iat[]

Q -2 Consider the folloowing dataframe and do as directed:

import pandas as pd

d={‘Mouse’:[150,200,300,400],

   ‘Keyboard’:[180,200,190,300],

   ‘Scanner’:[200,280,330,450]}

df=pd.DataFrame(d,index=[‘Jan’,’Feb’,’March’,’April’])

A. Write code to access data of Mouse and Scanner columns.

print(df[[‘Mouse’,’Scanner’]])

B. Write code to access data of the Keyboard column using dot notation and column name.

print(df.Keybaord)

C. Write code to access data of scanners using loc[].

print(df.loc[:,’Scanner’])

D. Write code to access data of all columns where mouse data is more than 200.

print(df[df[‘Mouse’]>200])

E. Write code to access columns using 0 and 2.

print(df.iloc[:,[0,2]])

F. Write code to access data of rows of jan and march for scanner and keyboard.

print(df.loc[[‘Jan’,’March’],[‘Scanner’,’Keyboard’]])

The next section of important Dataframe class 12 questions and answers consists of the questions based on output. 

  • Consider the above dataframe and predict the output:

a)       print(df.iloc[1][2]) → 280

b)      print(df.loc[‘Feb’,’Scanner’]) →  280

c)       df1=df[df[‘Keyboard’]>190] 

       print(df1[[‘Mouse’,’Scanner’]])      Mouse  Scanner

                                                        Feb      200      280

                                                        April    400      450

d)      print(df.iat[2,1]) → 190

The next section of important Dataframe class 12 questions and answers consists of error-based questions. 

  •         Consider the above dataframe and find out errors in following code fragment:

a.       df[1,3] èCorrection: df.iloc[:,[1.3]]

b.       df.loc[2,2] èCorrection: loc needs index of row and column, df.loc[‘March’,’Scanner’]

c.       df.at[1][1]èCorrection: at also required coloumn name, df.at[‘Feb’,’Keyboard’]

d.       df.iloc[0;2,1] èCorrection: Semicolon will be replaced with :, df.iloc[0:2,1]

  •        Explain following code lines in your words, what it will do:

a. df.iloc[:2,] → It will access row indexes from 0:2 (exclude 2) and all columns of dataframe.

b. df.loc[:,’Mouse’] → It will access mouse data with all rows.

c. df.at[‘March’,’Scanner’] → Access Scanner details of March Month.

d. df.iloc[2,0] → Access the value located at row index 2 (‘Macrh’) and column index 0 (Mouse)

e.       df.iloc[0:2,0:1] → It will access rows ranges 0 to 2 and columns 0 to 1 excluding upper limit index number.

f.        df.iloc[:,2] → Access all rows and column index 2.

Q – 3 What is the difference between loc[] and iloc[]?

Ans.: Both are used to access data from dataframe with a list of rows and columns. Loc requires column names whereas iloc requires index number.
 
Q – 4 What is the difference between at[] and iat[]?
Ans.: Similar to above only just replace the words loc[] and iloc[] with at[] and iat[].

Click here to read more questions and download pdf for Dataframe condition-based questions.

That’s all from important Dataframe class 12 questions and answers for the topic select/access data from dataframe. I hope you understand the concept very well. Kindly share your feedback in the comment section for this article’s important Dataframe class 12 questions and answers. 
 
Follow this link to read more about informatics practices class 12 notes, assignments and practicals.
 
 

Informatics Practices with python class 12

Leave a Reply