wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

class 12_dataframes_1

Total questions: 35

Worksheet time: 18mins

Name
Class
Date
1.

Best way to import the pandas module in your program ?

a)

1.import pandas

b)

2.import pandas as pd

c)

3.from pandas import *

d)

4.All of the above

2.

we can analyze the data in pandas with :

a)

Series

b)

Dataframe

c)

Both

d)

none

3.

DataFrame is .......................

a)

size mutable, data mutable

b)

size immutable, data mutable

4.

An empty DataFrame can be created by.................

a)

passing arguments

b)

without passing arguments

5.

Which of the functions can be used to delete column/row from a DataFrame?

a)

pop()

b)

at()

c)

drop()

d)

iloc()

6.

Dataframe can contain multiple series

a)

True

b)

False

7.

DataFrame in pandas is

a)

1. dimensional array

b)

2. dimensional array

c)

3.dimensional array

d)

4.None of the above

8.

Not a function of Dataframe

a)

Head()

b)

Tail()

c)

loc()

d)

multi()

9.

Which of the following can be used to make a Dataframe?

a)

Series

b)

DataFrame

c)

Structured ndarray

d)

All of the above

10.

Type the syntax that returns the top 5 rows in DataFrame df with the native Pandas function (not slicing):

(a)  

11.

Find the missing word:


import pandas as pd


students=pd._____________ ([["Khalid", 15]])

a)

pandas

b)

DataFrame

c)

dataframe

12.

Which brackets are correct:


students=pd.DataFrame_ _ _ "Khalid", 15]])

a)

( [ [

b)

((

c)

( [ [ [ [

13.
A Dataframe has axes column index (axis=0) row index (axes=1)
a)
true
b)
false
14.
df[empid] & df.empid are same
a)
true
b)
false
15.
print(df.iloc[5]) will give output
a)
first five rows
b)
0-4 rows
c)
only 5th row
d)
Error in syntax
16.

The instructor wants to add a new column, Marks to the dataframe. The values of the marks will be 12, 22, 21, 24. Help him to choose the correct command to do so.

a)

a) Df.columns=[12, 22, 21, 24]

b)

b) df[‘marks’] = [12, 22, 21, 24]

c)

c) df.loc[marks] = [12, 22, 21, 24]

d)

d) Both (b) and (c) are correct

17.

Which of the following commands is used to convert array named "grades" into data frame named "df_grades"?

a)

df_grades = grades

b)

df_grades = pd.DataFrame(grades)

c)

df_grades = pd.DataFrame("grades")

d)

grades = pd.DataFrame(df_grades)

18.

_________ function is used to access individual values

a)

it ()

b)

bit ()

c)

at ()

d)

set ()

19.

___________ attribute is used to specify column labels

a)

column ()

b)

column

c)

columns()

d)

columns

20.

To get number of elements in a DataFrame _____ attribute may be used.

a)

size

b)

shape

c)

values

d)

ndim

21.

For the given DataFrame df, what will be the code to get the value 38?

a)

df . iloc [1,1]

b)

df . Age [222]

c)

df . iat [1,1]

d)

df . at [222,'Age']

22.

Given the dataframe

d1=pd.DataFrame( {'A':[1,2,3],'B':[4,5,6],'C':[7,8,9] } ) .

Find the output of print(d1.loc['A':'B',:]

a)

0 1 2

A 1 2 3

B 4 5 6

b)

0 1 2

A 1 2 3

c)

0 1 2

B 4 5 6

23.

Given a dataframe df with 2 columns rollno and age .Find out the right code to add a new column class and assign a values NaN

a)

df.class=np.NaN

b)

df['class']=np.NaN

c)

df['class']=[np.NaN]

24.

Given the dataframe df=

Toys Books

EKM 789 234

TVM 567 456

CLT 459 345

Find the result of df.loc['EKM','Toys':'Books']=[700,800]

a)

Toys Books

EKM 789 234

TVM 567 456

CLT 459 345

b)

Toys Books

EKM 789 234

TVM 700 800

CLT 459 345

c)

Toys Books

EKM 700 800

TVM 567 456

CLT 459 345

d)

Toys Books

EKM 789 234

TVM 567 456

CLT 459 345

25.

Which function in Pandas is used for deleting rows?

a)

delete()

b)

del()

c)

cut()

d)

drop()

26.

For selecting rows by an integer location, which function do we use in Pandas?

a)

loc()

b)

iloc()

c)

pop()

d)

append()

27.

Consider the given dataframe df.

Rename the columns 'JAN' ,'FEB' to 'JANUARY' and 'FEBRUARY' and the index 'P1' to 'P100'.

Among the following which one is correct?

a)

df=df.rename(index={'P1':'P100'},columns={'JAN':'JANUARY','FEB':'FEBRUARY'})

b)

df.rename(index={'P1':'P100'},columns={'JAN':'JANUARY','FEB':'FEBRUARY'})

c)

df.rename(index={'P1':'P100'},columns={'JAN':'JANUARY','FEB':'FEBRUARY'},inplace=True)

28.
print(df.tail()) will give output
a)
first five rows
b)
last five rows
c)
only last 01 row
d)
Error in syntax
29.

To iterate over horizontal subsets of DataFrame __________function may be used.

a)

iterate

b)

itercols( )

c)

iterrows( )

d)

iteritems( )

30.

The __________ attribute of a dataframe object returns the row labels of the dataframe.

a)

index

b)

rows

c)

columns

d)

values

31.

To obtain the number of axes or array dimensions of a dataframe object, you can check _____ attribute of the dataframe.

a)

index

b)

size

c)

ndim

d)

shape

32.

To extract row/column from a dataframe, ______ function may be used.

a)

row()

b)

column()

c)

loc()

d)

All of these

33.

DataFramedf

Age Name

rank1 28 Tom

rank2 34 Jack

rank3 29 Steve

rank4 42 Ricky

Find out the command used to get the following output from the above dataframe,

Age

rank1 28

rank2 34

rank3 29

rank4 42

a)

Print(df[‘Age’])

b)

print(df[‘Age’])

c)

print(df(‘Age’))

d)

Print(df[‘Age’], axis=1)

34.

Predict the o/p of the following:

import pandas as pd

x=["ab",'cd','ef','gh']

df=pd.DataFrame(x)

print(df[-2:])

a)

0

2 ef

3 gh

b)

0

1 cd

2 ef

3 gh

c)

0

3 ef

2 gh

35.

Given the dataframe

d1=pd.DataFrame( {'A':[1,2,3],'B':[4,5,6],'C':[7,8,9] } ) .

Find the output of print(d1.loc['A':'B',:]

a)

A 1 2 3

B 4 5 6

b)

0 1 2

A 1 2 3

c)

0 1 2

B 4 5 6