Numpy and Pandas Quiz

Numpy and Pandas Quiz

University

10 Qs

quiz-placeholder

Similar activities

Post-test array c++

Post-test array c++

University

10 Qs

Quiz on Object Oriented Programming and Java

Quiz on Object Oriented Programming and Java

University

15 Qs

Python for Data Analysis Quiz 10

Python for Data Analysis Quiz 10

University

10 Qs

Python Functions and Data Structures Quiz

Python Functions and Data Structures Quiz

University

10 Qs

Python Numpy and Pandas Quiz

Python Numpy and Pandas Quiz

University

15 Qs

Arrays

Arrays

University

15 Qs

Java Arrays

Java Arrays

5th Grade - University

10 Qs

Data Structure 1

Data Structure 1

University

10 Qs

Numpy and Pandas Quiz

Numpy and Pandas Quiz

Assessment

Quiz

Other

University

Hard

Created by

Singaravelan Giridharan

Used 3+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What does the following NumPy code output? import numpy as np arr = np.array([1, 2, 3, 4]) print(arr.shape)
(4,)
(1, 4)
(4, 1)
4

Answer explanation

A 1D NumPy array has a shape of (n,) where n is the number of elements.

2.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What is the output of this NumPy operation? import numpy as np arr = np.array([10, 20, 30]) print(arr * 2)
[10, 20, 30, 10, 20, 30]
[20, 40, 60]
[102, 202, 302]
Error

Answer explanation

NumPy broadcasts 2 across the entire array and multiplies each element.

3.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will the following code output? import numpy as np arr = np.array([[1, 2], [3, 4]]) print(arr.T)
[[1, 3], [2, 4]]
[[1, 2], [3, 4]]
[[1, 2, 3, 4]]
Error

Answer explanation

arr.T transposes the matrix, swapping rows and columns.

4.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What does np.zeros((2,3)) create?
A 2D array filled with random values
A 2D array of shape (2,3) filled with 0s
A 1D array of length 6 filled with 0s
An error because NumPy does not support zero arrays

Answer explanation

np.zeros((2,3)) creates a 2-row, 3-column matrix filled with zeros.

5.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

import numpy as np

arr = np.array(['A', 'B', 'C', 'D'])

print(arr.dtype)

What will be the output of the following code?

int32

float64

U1

Error

Answer explanation

np.arange(start, stop, step) generates numbers starting from 3 up to 10 (exclusive), incrementing by 2.

6.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What does the following pandas code output? import pandas as pd data = {'A': [1, 2, 3], 'B': [4, 5, 6]} df = pd.DataFrame(data) print(df.shape)
(3, 2)
(2, 3)
(3, 3)
(6,)

Answer explanation

The DataFrame has 3 rows and 2 columns, so df.shape returns (3, 2).

7.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will df.head(2) return? import pandas as pd df = pd.DataFrame({'A': [10, 20, 30], 'B': [40, 50, 60]}) print(df.head(2))
The first 2 rows of the DataFrame
The last 2 rows of the DataFrame
The entire DataFrame
An error

Answer explanation

df.head(n) returns the first n rows of the DataFrame.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?