wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Pandas

Total questions: 20

Worksheet time: 7mins

Name
Class
Date
1.

What does the df.head(5) function do in pandas?

a)

Shows the last 5 rows

b)

Shows the first 5 rows

c)

Deletes the first 5 rows

d)

Returns column names

2.

Which of the following creates a DataFrame from a dictionary?

a)

df = pandas.Series({‘a’: 1, ‘b’: 2})

b)

df = pandas.DataFrame([1,2,3])

c)

df = pandas.DataFrame({‘a’: [1,2], ‘b’: [3,4]})

d)

df = pandas.read_dict({‘a’: [1,2], ‘b’: [3,4]})

3.

What does df.groupby('column_name') return?

a)

A grouped object that can be aggregated

b)

A sorted DataFrame

c)

A filtered DataFrame

d)

A new column

4.

What will df.iloc[2, 1] return?

a)

A list of two values

b)

The 2nd row, 1st column value

c)

The 3rd row, 2nd column value

d)

An error

5.

Which pandas function helps combine multiple DataFrames vertically (row-wise)?

a)

concat()

b)

merge()

c)

combine()

d)

join()

6.

What is the default axis for df.sum()?

a)

1 (row-wise)

b)

None

c)

It doesn’t have a default

d)

0 (column-wise)

7.

What does df.sort_values(by='price', ascending=False) do?

a)

Sorts rows by column price in ascending order

b)

Sorts columns in descending order

c)

Sorts rows by column price in descending order

d)

Throws an error

8.

What is the result of df['A'] > 10?

a)

A list of values greater than 10

b)

A Series of Boolean values

c)

An error

d)

A filtered DataFrame

9.

Which of the following returns summary statistics of numerical columns?


a)

df.describe()

b)

df.stats()

c)

df.summary()

d)

df.profile()

10.

What does df.isnull().sum() return?

a)

Total number of missing values

b)

Sum of all non-null entries

c)

A DataFrame of all missing values

d)

Count of NaNs in each column

11.

Which method is used to return a DataFrame with duplicate rows removed?

a)

dropna()

b)

remove_duplicates()

c)

drop_duplicates()

d)

filter_duplicates()

12.

What does df.loc[2] return?


a)

Row number 2 (zero-based)

b)

Only the value of column index 2

c)

Row with index label 2

d)

Value in row 2 and column labeled ‘2’

13.

What does df.value_counts() return when applied to a Series?

a)

Count of unique values in that Series

b)

Count of column names

c)

Count of nulls

d)

Frequency of rows

14.

What does df.groupby('brand')['price'].mean() return?

a)

A pivot table

b)

Grouped average of prices by brand

c)

Mean price across all brands

d)

Total price for each brand

15.

Which of the following fills missing values forward (downward) in a column?

a)

df.fillna(method='ffill')

b)

df.fillna('forward')

c)

df.interpolate()

d)

df.fillna(method='bfill')

16.

What does df[df['age'] > 30] return?

a)

Error

b)

Only the age column

c)

Boolean array

d)

All rows where 'age' is greater than 30

17.

Which method combines two DataFrames side-by-side by column?

a)

df1.combine_first(df2)

b)

pd.concat([df1, df2], axis=1)

c)

df1.merge(df2)

d)

df1.append(df2)

18.

What will df[df.duplicated()] return?

a)

Only rows that are not duplicated

b)

Boolean list of duplicated rows

c)

Count of duplicates

d)

DataFrame with duplicate rows

19.

What will df.groupby('gender')['income'].mean() return?

a)

Median income per gender

b)

Mean income per gender

c)

A DataFrame with all columns

d)

Count of gender-wise records

20.

 To drop a row with a specific index value '5', you should use:

a)

df.drop('5', axis=1)

b)

df.remove(5)

c)

df.drop(index=5)

d)

df.drop(5)