CSE 6040 FINAL EXAM 2026/2027 COMPLETE (150)
CURRENT TESTING QUESTIONS AND CORRECT
ANSWERS WITH DETAILED RATIONALES.
CSE 6040
Prepare effectively for the CSE 6040 Final Exam with this focused study resource. It
supports review of core data science and computing concepts, programming, data
analysis, algorithms, and problem-solving techniques relevant to the course. Use the
material to reinforce your understanding, review key topics, and identify areas that
may require additional study. This resource is suited for CSE 6040 students, data
science learners, and candidates preparing for the final examination.
MULTIPLE CHOICE.
SECTION 1: PYTHON & PANDAS FUNDAMENTALS (Questions 1–50)
1. You are given a Python dictionary d = {'a': [1, 2, 3], 'b': (4, 5), 'c': 6}. What is
the result of len(d['a']) + len(d['b'])?
(A) 3
(B) 5
(C) 6
(D) TypeError
Answer: (B) 5
Rationale: d['a'] is a list of length 3, and d['b'] is a tuple of length 2. The sum
is 3 + 2 = 5. d['c'] is an integer, not a collection. This tests your ability to work
with nested data structures and understand Python's basic types.
2. Which of the following is the correct way to merge two pandas
DataFrames df1 and df2 on a common column named 'id' using an inner
join?
(A) df1.merge(df2, on='id', how='inner')
, Page 2 of 65
(B) df1.join(df2, on='id', how='inner')
(C) pd.concat([df1, df2], axis=1, join='inner')
(D) df1.combine(df2, on='id')
Answer: (A) df1.merge(df2, on='id', how='inner')
Rationale: The merge() function is the primary method for joining DataFrames
on a key column. The how='inner' parameter specifies an inner join. join() (B)
is used for joining on indexes. concat() (C) is used for concatenation, not
merging on a key. combine() (D) is not a standard pandas method for this
purpose.
3. A pandas Series s contains the values [10, 20, 30, 40, 50]. What is the
result of s[s > 30]?
(A) [40, 50]
(B) [30, 40, 50]
(C) A Series with index labels and values 40 and 50
(D) A boolean Series [False, False, False, True, True]
Answer: (C) A Series with index labels and values 40 and 50
Rationale: This is boolean indexing. s > 30 creates a boolean mask. Applying
this mask to the Series returns a new Series containing only the elements
where the condition is True (40 and 50). The result is a Series, not a list (A).
Option D is the mask itself, not the result of the indexing.
4. In pandas, what is the primary purpose of the groupby() function?
(A) To filter rows based on a condition
(B) To split data into groups based on some criteria and apply a function to
each group
(C) To merge two DataFrames
, Page 3 of 65
(D) To reshape data from wide to long format
Answer: (B) To split data into groups based on some criteria and apply a
function to each group
Rationale: The split-apply-combine strategy is the core of groupby(). It is used
to perform aggregate operations (like sum, mean, count) on subsets of data.
Filtering (A) is typically done with boolean indexing. Merging (C) is done
with merge(). Reshaping (D) is done with melt() or pivot().
5. You have a pandas DataFrame df with columns 'A', 'B', and 'C'. How can
you select only rows where the value in column 'A' is greater than 5 and
the value in column 'B' is less than 10?
(A) df[(df['A'] > 5) & (df['B'] < 10)]
(B) df[df['A'] > 5 and df['B'] < 10]
(C) df.query('A > 5 & B < 10')
(D) Both A and C
Answer: (D) Both A and C
Rationale: Both boolean indexing with the & operator (A) and
the query() method (C) are valid ways to filter a DataFrame. In (A), parentheses
are required around each condition due to operator precedence. In (B), using
the Python and keyword will cause an error with Series objects.
The query() method (C) is a concise and often faster alternative.
6. What does the pandas apply() method do when used on a DataFrame?
(A) It applies a function to every element in the DataFrame.
(B) It applies a function along an axis of the DataFrame (rows or columns).
(C) It applies a function to the entire DataFrame at once.
(D) It is used to apply a function to a single column only.
, Page 4 of 65
Answer: (B) It applies a function along an axis of the DataFrame (rows or
columns).
Rationale: The apply() method is used to apply a function to each row (axis=1)
or each column (axis=0). It is more flexible than applymap(), which applies a
function element-wise (A). It does not operate on the entire DataFrame at
once (C). It can be used on a single column (D) but that is not its primary or
exclusive purpose.
7. A pandas Series contains missing values represented as NaN. Which
method is used to drop all rows containing any NaN values?
(A) s.dropna()
(B) s.fillna(0)
(C) s.isna()
(D) s.drop_duplicates()
Answer: (A) s.dropna()
Rationale: dropna() removes rows (or columns) containing missing
values. fillna(0) (B) replaces NaN with 0. isna() (C) returns a boolean mask of
missing values. drop_duplicates() (D) removes duplicate rows.
8. In pandas, what is the difference between a Series and a DataFrame?
(A) A Series is one-dimensional, while a DataFrame is two-dimensional.
(B) A Series can only hold numeric data.
(C) A DataFrame is immutable.
(D) There is no difference; they are the same.
Answer: (A) A Series is one-dimensional, while a DataFrame is two-
dimensional.