Important QnA – Dataframe functions for IP class 12

In this article we will discuss QnA – Dataframe functions.

Objective Type Questions – dataframe functions

Click here to read the notes for the same.

Fill in the blanks:

  1. A _________function is used to display top rows (n) from dataframe.
  2. A _______ function is used to display bottom rows (n) from dataframe.
  3. _____ refers to passing True and False value as an index in Dataframes.
  4. To pass index label _________ keyword is used to in pd.dataFrame() function.
  5. By default you can display ____ no. of top/bottom rows using head()/tail() function.

Fill in the blanks Answers for dataframe functions:

  1. head()
  2. tail()
  3. ignore_index
  4. index
  5. 5 (five)
NameCityEmailFees
0AkshAhmedabadaksh123@gmail.com15000
1BhavinBarodabhavin000@gmail.com25000
2CharuSuratcharu123@gmail.com12000
3DharaAnanddhara174@gmail.com11000
Consider this Dataframe from all questions given below

Now in the nest section we will see MCQs from the Dataframe functions topic:

MCQs

1 Choose the correct function to rename city columns to location using rename() function:

a. df.rename(columns={‘City’:’Location’})

b. df.rename(columns={‘City’=’Location’})

c. df.rename(‘City’=’Location’)

d. df.rename(df.columns(‘City’,’Location’))

2 Which of the following statement(s) is/are correct with respect to df.columns properties to rename columns

  1. All columns must be specified
  2. Columns must be in the form of a list
  3. Old column names not required
  4. Columns can be specified with columns number

a Only 1 is correct

b 1, 2 and 3 are correct

c 1 and 3 are correct

d All of them are correct

3 df.index properties ca be used to

a rename rows

b rename columns

c rename rows and columns both

d None of these

4. To display 2 rows from the top in the dataframe, which of the following statement is correct:

a df.head()=2

b. df.head(n=2)

c. df.head(range(2))

d. All of the above

Error based Questions – Dataframe functions

  1. Find errors from the given code fragments:
df.DataFrame({'S.NO':[1,2,3],'Name':['Sapan','Vivek','Vishal']})
df.rename[{'S.No':'SNO','Name':'Sname'}]
df.index=(1,2,3)
ErrorsCorrection
Line 1: Dataframe Object is missingdf = pd.DataFrame({‘S.NO’:[1,2,3],’Name’:[‘Sapan’,’Vivek’,’Vishal’]})
Line 2: columns keyword is missing, and rename is a function so bracket needs to be replaced to correctdf.rename(columns={‘S.No’:’SNO’,’Name’:’Sname’})
Lines 3: index properties requires a list not in a tuple formdf.index=[1,2,3]

2.

df.DataFrame({'S.NO':[1,2,3],'Name':['Sapan','Vivek','Vishal']})
df.columns=('SNO','Name')
df.index=[1 to 3]

3.

df.DataFrame({'S.NO':[1,2,3],'Name':['Sapan','Vivek','Vishal']})
df.head(3)
df.tail(3)

Application Based questions

Watch this video understand the topic and answers.

1 Consider above dataframe and rename columns using rename() function and df.columns properties.

Old column Names : City, Email, Fees

New Column Names: Location, ContactDetals, Charges

Sol.

1 Using Rename Function:

df.rename(columns={'City':'Location','Email':'ContactDetails','Charges'})

2 Using columns properties:

df.columns=['Location','ContactDetails','Charges']

2 Consider above dataframe and rename rows using rename() function and df.index properties.

New indexes: 1,2,3,4

Sol.

1 Using rename function:

df.rename(index={0:1,1:2,2:3,3:4})

2 Using index properties:

df.index=[1,2,3,4]

3 Write a statement to rename rows and columns together for the dataframe.

df.rename(columns={'City':'Location','Email':'ContactDetails','Fees':'Charges'}, index={0:1,1:2,2:3,3:4})

4 Write statement to display top and botton 3 rows from dataframe.

Sol.:

print(df.head(3))  or   print(df.head(n=3)) 
print(df.head(3))  or   df.tail(n=3)

Click here to read topic wise notes, assignments and practical questions for class 12 IP.

Thank you reading the complete article. Share your feedback and share this article in your circle. Leave your reply about this post in comment section.

2 thoughts on “Important QnA – Dataframe functions for IP class 12”

  1. Rekha

    Plz give answers of this questions.

Comment Your Views

%d bloggers like this: