Unit 4: Data Analysis with NumPy and Pandas - Practice Quiz
1
Which function is commonly used to create a NumPy ndarray from a Python list?
np.frame()
np.list()
np.series()
np.array()
2 Which attribute gives the data type of the elements in a NumPy array?
size
dtype
ndim
shape
3 Which NumPy attribute returns the number of dimensions in an array?
size
dtype
ndim
shape
4
What is the shape of np.array([[1, 2, 3], [4, 5, 6]])?
(6, 1)
(3, 2)
(1, 6)
(2, 3)
5
Given a = np.array([10, 20, 30]), which expression accesses 20?
a[2]
a[1]
a[3]
a[0]
6
Given a = np.array([[1, 2], [3, 4]]), which expression accesses 4?
a[1, 0]
a[0, 0]
a[1, 1]
a[0, 1]
7 Which method changes the shape of a NumPy array without changing its data?
convert()
remove()
reshape()
replace()
8 Which NumPy function joins arrays along an existing axis?
np.calculate()
np.contains()
np.compare()
np.concatenate()
9
What does the term ndarray mean in NumPy?
10 Which NumPy function creates an array filled with zeros?
np.arange()
np.linspace()
np.empty()
np.zeros()
11 Which Pandas object represents one-dimensional labeled data?
DataFrame
ndarray
Series
IndexFrame
12 Which Pandas object is commonly used for two-dimensional tabular data?
Series
ArrayList
DataTable
DataFrame
13 Which Pandas function reads data from a CSV file?
pd.import_csv()
pd.read_csv()
pd.open_csv()
pd.load_csv()
14 Which Pandas function reads tables from an HTML page?
pd.load_html()
pd.import_html()
pd.read_html()
pd.open_html()
15 Which method displays the first few rows of a Pandas DataFrame?
shape()
info()
head()
tail()
16 Which DataFrame attribute returns the number of rows and columns?
ndim
dtypes
shape
size
17 Which Pandas method applies a function to values along a DataFrame axis?
merge()
drop()
apply()
rename()
18 Which function can calculate the average of numeric values in a Pandas column?
count()
sum()
mean()
max()
19 Which Pandas method detects missing values in a DataFrame?
fillna()
isnull()
dropna()
replace()
20 Which Pandas method removes rows or columns containing missing values?
fillna()
isna()
dropna()
notna()
21
What is the main advantage of using a NumPy ndarray instead of a Python list for numerical calculations?
22
Given a = np.array([[1, 2, 3], [4, 5, 6]]), what are a.ndim and a.shape, respectively?
3 and (2, 3, 1)
2 and (2, 3)
1 and (6,)
2 and (3, 2)
23
For a = np.array([[10, 20, 30], [40, 50, 60]]), which expression returns the value 50?
a[1, 0]
a[0, 1]
a[2, 1]
a[1, 1]
24
What is the result of np.reshape(np.arange(6), (3, 2))?
[[1, 2], [3, 4], [5, 6]]
[[0, 1, 2], [3, 4, 5]]
[[0, 2, 4], [1, 3, 5]]
[[0, 1], [2, 3], [4, 5]]
25
If a = np.zeros((2, 3, 4)), how many elements does a contain?
26
What is the shape of the array created by np.ones((4, 1, 2))?
(4, 1, 2)
(4, 2)
(1, 4, 2)
(2, 1, 4)
27
For a = np.array([5, 10, 15, 20, 25]), what values are returned by a[1:4]?
[10, 15, 20, 25]
[15, 20, 25]
[5, 10, 15]
[10, 15, 20]
28
What does np.concatenate((a, b), axis=0) do when a and b are two-dimensional arrays with the same number of columns?
29
Given a = np.array([2, 4, 6]), what is the result of a * 3 + 1?
[7, 13, 19]
[9, 15, 21]
[6, 12, 18]
[3, 5, 7]
30 Which Pandas structure is most appropriate for representing tabular data with labeled rows and columns?
Series
DataFrame
Index
31
What does df['Sales'] generally return when df is a Pandas DataFrame containing a column named Sales?
Series
32
Which statement correctly loads a CSV file named sales.csv into a Pandas DataFrame?
pd.read_csv('sales.csv')
pd.load_csv('sales.csv')
pd.import_csv('sales.csv')
pd.DataFrame.csv('sales.csv')
33
What does pd.read_html('page.html') typically return?
DataFrame objects
34
Which expression selects rows from df where the Age column is greater than 30?
df[df['Age'] > 30]
df['Age' > 30]
df.where('Age' > 30)
df.select(Age > 30)
35
What is the purpose of df.groupby('Department')['Salary'].mean()?
36
What does df['Price'].apply(lambda x: x * 1.1) do?
37
Which statement applies a function to each row of a DataFrame named df?
df.function(axis='rows')
df.map(function, axis=1)
df.apply(function, axis=0)
df.apply(function, axis=1)
38
Which command removes rows containing at least one missing value from df?
df.remove_nulls()
df.dropna()
df.clearna()
df.delete(missing=True)
39
Which statement replaces missing values in the Score column with that column's mean?
df['Score'].fillna(0)
df['Score'].replace_mean(None)
df['Score'].fillna(df['Score'].mean())
df['Score'].dropna(df['Score'].mean())
40
What is the main purpose of df.drop_duplicates() during data cleaning?
41
What is printed by the following code?
a = np.arange(12).reshape(3, 4)
b = a[:, 1:3]
b += 100
c = a[[0, 2], [1, 2]]
print(c, np.shares_memory(a, b))
[101 110] True
[1 10] True
[101 110] False
[100 109] False
42
Given a = np.array([200, 250], dtype=np.uint8) and b = a + np.array([100], dtype=np.uint8), what are b.tolist() and b.sum()?
[300, 350] and 650
[44, 94] and 138
[44, 94] and 394
[255, 255] and 510
43
Arrays x and y have shapes (2, 1, 3) and (1, 4, 1), respectively. What is the shape of x + y under NumPy broadcasting?
(1, 4, 3)
(2, 1, 1)
(2, 4, 3)
(2, 4, 1)
44
If x.shape == (2, 3), what is the shape of np.expand_dims(x, axis=(0, -1))?
(1, 2, 1, 3)
(1, 2, 3, 1)
(1, 1, 2, 3)
(2, 1, 3, 1)
45
For a = np.arange(12).reshape(3, 4), what does a[[0, 2], [1, 3]] return?
array([[1, 3], [9, 11]])
array([1, 11])
array([[1, 11]])
array([3, 9])
46
Let x = np.arange(24).reshape(2, 3, 4). What is the result of x[:, [0, 2], [1, 3]]?
array([[1, 11], [13, 23]])
array([[1, 9], [15, 23]])
array([[1, 13], [11, 23]])
array([1, 11, 13, 23])
47
What does np.resize(np.array([1, 2, 3]), (2, 4)) produce?
array([[1, 2, 3, 0], [0, 0, 0, 0]])
array([[1, 2, 3, 2], [3, 1, 2, 3]])
array([[1, 2, 3, 1], [1, 2, 3, 1]])
array([[1, 2, 3, 1], [2, 3, 1, 2]])
48
If a and b both have shape (2, 3), what is the shape of np.stack([a, b], axis=1)?
(2, 6)
(2, 3, 2)
(4, 3)
(2, 2, 3)
49
Array A has shape (5, 1, 3, 4) and array B has shape (1, 7, 4, 2). What is the shape of A @ B?
(1, 7, 3, 2)
(5, 1, 3, 2)
(5, 7, 3, 2)
(5, 7, 4, 4)
50
Consider x = np.arange(120).reshape(2, 3, 4, 5) and y = np.moveaxis(x, (0, 3), (2, 0)). Which statement is correct?
y.shape == (5, 3, 4, 2) and y[1, 2, 0, 3] == 46
y.shape == (3, 5, 2, 4) and y[1, 2, 0, 3] == 56
y.shape == (5, 2, 3, 4) and y[1, 2, 0, 3] == 46
y.shape == (5, 3, 2, 4) and y[1, 2, 0, 3] == 56
51
Given s1 = pd.Series([10, 20], index=['a', 'b']) and s2 = pd.Series([1, 2], index=['b', 'c']), what does s1.add(s2, fill_value=0) contain?
a: NaN, b: 21.0, c: NaN
a: 10.0, b: 21.0, c: 2.0
a: 10.0, b: 20.0, c: 3.0
a: 11.0, b: 22.0, c: 2.0
52
What is s.tolist() after executing s = pd.Series([10, 20, 30], index=['a', 'a', 'b']) followed by s.loc['a'] += 5?
[15, 20, 30]
[15, 25, 30]
[15, 25, 35]
[10, 25, 30]
53
A CSV contains code values NA, Missing, and valid. It is read using pd.read_csv(file, keep_default_na=False, na_values=['Missing']). What is df['code'].isna().tolist()?
[True, False, False]
[False, False, False]
[False, True, False]
[True, True, False]
54
An HTML document contains three tables: a report table containing Revenue, a report table containing Costs, and an other table containing Revenue. What does pd.read_html(html, match='Revenue', attrs={'class': 'report'}) return?
report tables
55
A left DataFrame has key values [1, NaN, NaN], and a right DataFrame has key values [NaN, 2]. How many rows result from left.merge(right, on='key', how='inner')?
56
For df = pd.DataFrame({'g': ['A', 'A', 'B'], 'x': [1, 3, 10]}), what is (df['x'] - df.groupby('g')['x'].transform('mean')).tolist()?
[-1.0, 1.0, 8.0]
[1.0, 3.0, 10.0]
[-2.0, 0.0, 0.0]
[-1.0, 1.0, 0.0]
57
Let df = pd.DataFrame({'a': [3, 1], 'b': [2, 8]}) and r = df.apply(lambda s: pd.Series({'min': s.min(), 'span': s.max() - s.min()})). Which statement is correct?
r.shape == (2, 4) and r.loc['min', 'a'] == 3
r.shape == (2, 2) and r.loc['span', 'b'] == 7
r.shape == (4, 2) and r.loc['span', 'a'] == 1
r.shape == (2, 2) and r.loc['span', 'b'] == 6
58
What is the result of pd.Series([' a ', None]).map(str.strip, na_action='ignore').tolist()?
[' a ', None]
['a', 'None']
['a', None]
['a', NaN]
59
A DataFrame has id values [1, 1, 2, 3, 3]. Which IDs remain after df.drop_duplicates(subset=['id'], keep=False)?
1, 2, and second 3
1, 2, and first 3
2
1, 2, and 3
60
Given s = pd.Series([1.0, np.nan, np.nan, 4.0, np.nan]), what does s.interpolate(limit=1, limit_direction='both', limit_area='inside').tolist() produce?
[1.0, 2.0, 3.0, 4.0, NaN]
[1.0, 2.0, 3.0, 4.0, 4.0]
[1.0, NaN, 3.0, 4.0, 4.0]
[1.0, 2.0, NaN, 4.0, NaN]
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →