- Home
- Subjects
- Data Science
Data Science MCQs · Page 21
1,613 multiple choice questions with answers across 28 topics.
-
A
The last row of the frame only, because keep applies to the whole frame rather than rows
-
B
Both the first and last occurrences, since keep='last' keeps the boundary rows intact
-
C
The last occurrence of each email in the current row order, dropping the earlier ones
Correct answer
-
D
The first occurrence of each email address, because keep names the copy inspected
-
A
The two frames hold different row counts, which the validation step forbids
-
B
The key columns have different dtypes, so pandas cannot compare their values at all
-
C
The merge produced more columns than expected, exceeding the validation threshold
-
D
At least one side repeats a key value, so the join would produce duplicate rows
Correct answer
-
A
The cast truncates NaN to zero, raising a warning rather than an error
-
B
The fix is to cast to float16 first, because float16 supports missing values natively
-
C
int64 has no NaN representation, so the nullable Int64 dtype must be used instead
Correct answer
-
D
int64 holds NaN perfectly well, but the cast is refused because of an unrelated mismatch
-
A
The call groups by calendar month names, treating the strings as categorical data
-
B
An empty frame is returned, because no rows fall on the month-end timestamps
-
C
A TypeError about the index, because resample needs a DatetimeIndex on the axis
Correct answer
-
D
The string column is parsed automatically and the monthly totals are returned
-
A
1, 2, 2, 3, because dense ranking never leaves gaps after ties are collapsed
Correct answer
-
B
1, 2, 2, 4, because the next distinct value keeps its positional rank number
-
C
1, 2.5, 2.5, 4, because tied values receive the average of the positions they take
-
D
1, 1, 2, 3, because ties are ordered by their appearance and then renumbered
-
A
Because observed=True drops rows whose category does not appear among the group keys chosen
-
B
Because grouping a categorical converts it to an object column, losing category metadata
-
C
Because observed=True sorts the categories and then truncates the output index
-
D
Because the default expands every category combination, producing empty groups too
Correct answer
-
A
qcut, which uses sample quantiles, whereas cut splits on equal-width value ranges
Correct answer
-
B
cut, which uses sample quantiles, whereas qcut splits on equal-width value ranges
-
C
cut, because both functions are identical except for the naming of their labels
-
D
qcut, because it always produces equal-width bins regardless of the data distribution
-
A
A boolean Series aligned to the index, with NaN rows marked False unless NaN is listed
Correct answer
-
B
A boolean Series of identical length, with NaN rows marked True so every record is kept
-
C
An integer array of row positions, because isin returns the matching row numbers
-
D
A filtered DataFrame directly, since isin applies the mask as soon as it is called
-
A
df.transpose, which swaps rows and columns and therefore creates a long form table
-
B
df.melt with id_vars, which turns the monthly columns into rows of key-value pairs
Correct answer
-
C
df.pivot with the month columns as index, which expands the columns into extra rows
-
D
df.stack on axis=1, which returns a wide frame with the months kept as columns
-
A
Scattered in place, because pandas leaves NaN rows where they originally stood
-
B
The call raises, because sorting a column with NaN requires dropna first
-
C
At the end by default, because na_position defaults to last in sort_values
Correct answer
-
D
At the beginning by default, because NaN sorts before every numeric value
-
A
The duplicate cells are averaged, because the default aggregation is the mean
Correct answer
-
B
A ValueError is raised, because duplicate entries need an explicit aggfunc
-
C
The last row for each cell wins, because pivot_table keeps the final value
-
D
The rows are concatenated into a list inside the cell, preserving every value
-
A
CAST(order_date AS TEXT) LIKE '2024%', which cannot use the index
-
B
order_date + INTERVAL '1 day' = '2024-06-01', a computed date
-
C
order_date >= '2024-01-01' AND order_date < '2025-01-01'
Correct answer
-
D
EXTRACT(YEAR FROM order_date) = 2024, which scans every row
-
A
TRUNCATE accepts a WHERE clause but is slower than DELETE, because it scans the whole table row by row
-
B
Both fire row-level triggers once per removed row, so auditing behaves exactly the same for the two statements here
-
C
DELETE cannot be rolled back in any database, while TRUNCATE always can, because it is DDL and not DML
-
D
TRUNCATE removes all rows in one operation, cannot take a WHERE clause and fires no row-level delete triggers
Correct answer
-
A
The store's average sales, with 0 substituted wherever the partition is empty or has one row
-
B
The next month's sales within the same store, with 0 substituted for the last row of each partition
-
C
The running total of sales within each store, starting at 0 at the very first row of every partition here
-
D
The previous month's sales within the same store, with 0 substituted for the first row of each partition
Correct answer
-
A
Because NOT IN converts the NULL to zero and then compares numerically, matching every zero value
-
B
Because x <> NULL is UNKNOWN, so the NOT IN predicate can never be TRUE; NOT EXISTS is null-safe
Correct answer
-
C
Because the subquery is executed only when it contains no NULL values, and otherwise the whole subquery is skipped
-
D
Because NOT IN is not valid with a subquery at all, so the parser rejects the statement outright
-
A
UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates
Correct answer
-
B
Both remove duplicate rows, differing only in the column ordering they produce, so the choice between them is purely cosmetic
-
C
UNION requires matching column names, while UNION ALL does not, which is why UNION ALL is faster to write
-
D
UNION ALL removes duplicate rows, while UNION keeps them, so the two operators are exact opposites in effect
-
A
20, because the median of the three values is used instead of the mean
-
B
NULL, because any NULL in the input makes the aggregate NULL
-
C
15, because the NULL is excluded from both the sum and the count
Correct answer
-
D
10, because the NULL is treated as a zero value in the average
-
A
The rows are excluded from the result entirely, because the grouping key is missing
-
B
The query fails unless NULLs are filtered out first, since grouping needs a known key
-
C
All NULLs form a single group, because GROUP BY treats them as equal to each other
Correct answer
-
D
Each NULL forms its own separate group, because NULL is never equal to another one
-
A
Because COUNT(*) ignores NULLs in the customer key, so rows with a missing key are never counted at all by the aggregate
-
B
The one-to-many join repeats each customer row per order, so COUNT(DISTINCT customer_id) or a subquery gives the true count
Correct answer
-
C
Because the join sorts the rows and duplicates them during the sort, so the sort key must therefore be made distinct first of all
-
D
Because COUNT(*) counts columns rather than rows, so it returns the width of the joined result instead of its height
-
A
It includes them only if the column is indexed, since the index stores a default value
-
B
It includes them, because NULL differs from every value including the string x
-
C
It excludes them, because NULL <> 'x' evaluates to UNKNOWN rather than TRUE
Correct answer
-
D
It raises an error unless col is declared NOT NULL, because the comparison is invalid
-
A
Nothing changes, because the optimiser moves the predicate into the ON clause
-
B
All inactive matches are kept while unmatched rows are duplicated
-
C
The query fails because WHERE cannot reference the right table
-
D
Rows with no matching b row are removed, turning the outer join into an effective inner join
Correct answer
-
A
1,2,3 for all three functions, because every row receives a distinct sequential position
-
B
1,1,2 for RANK and 1,1,3 for DENSE_RANK, with 1,2,3 for ROW_NUMBER in the very same single query
-
C
1,1,3 for RANK; 1,1,2 for DENSE_RANK; and 1,2,3 for ROW_NUMBER with an arbitrary tie order
Correct answer
-
D
1,1,3 for all three, since ties always skip a position whatever function is used
-
A
RANGE requires a PARTITION BY clause, whereas ROWS can be used over the whole table without one
-
B
ROWS ignores the ORDER BY, whereas RANGE sorts the partition before summing
-
C
Rows that tie on d are all included in the same running total under RANGE, while ROWS admits them one at a time
Correct answer
-
D
RANGE includes only the current row, whereas ROWS accumulates every preceding row in the partition
-
A
10 and 7
Correct answer
-
B
7 and 7
-
C
10 and 10
-
D
7 and 10
-
A
The precision-recall curve, which plots precision against recall at every threshold
-
B
The validation curve, which plots scores against one hyperparameter value at a time
-
C
The ROC curve, which plots the true positive rate against the false positive rate of the model
-
D
The learning curve, which plots training and validation scores against training-set size
Correct answer