Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 10 MCQsData cleanup
ECAP776 ·
60 questions. Pick an option to check it.
Which pandas method displays the first few rows of a DataFrame?
Not quite. Try another option.
Answer: df.head()
df.head() displays the first five rows by default, helping you quickly inspect the data.
Question 2 of 60 · Investigation · Easy
Which DataFrame attribute returns the number of rows and columns?
Not quite. Try another option.
Answer: df.shape
df.shape returns a tuple containing the number of rows and columns.
Question 3 of 60 · Investigation · Easy
Which pandas expression counts missing values in each column?
Not quite. Try another option.
Answer: df.isna().sum()
isna() marks missing values as True, and sum() counts them in each column.
Question 4 of 60 · Investigation · Easy
Which method identifies duplicate rows in a pandas DataFrame?
Not quite. Try another option.
Answer: df.duplicated()
df.duplicated() returns a Boolean value for each row indicating whether it is a duplicate.
Question 5 of 60 · Investigation · Easy
What does df.info() mainly show?
Not quite. Try another option.
Answer: Column types and non-null counts
df.info() summarizes columns, data types, non-null counts, and memory usage.
Question 6 of 60 · Investigation · Easy
Which method returns the distinct values in a pandas Series named colors?
Not quite. Try another option.
Answer: colors.unique()
colors.unique() returns each distinct value found in the Series.
Question 7 of 60 · Investigation · Easy
Which method provides summary statistics such as count, mean, and standard deviation for numeric columns?
Not quite. Try another option.
Answer: df.describe()
df.describe() generates common descriptive statistics for numeric columns.
Question 8 of 60 · Matching · Easy
Which operator checks whether two Python values are equal?
Not quite. Try another option.
Answer: ==
The == operator compares two values and returns True when they are equal.
Question 9 of 60 · Matching · Easy
Which pandas method checks whether Series values appear in a given list?
Not quite. Try another option.
Answer: isin()
isin() returns True for values that are present in the supplied list or collection.
Question 10 of 60 · Matching · Easy
Which expression finds rows where the city column contains the text York?
Not quite. Try another option.
Answer: df['city'].str.contains('York')
str.contains('York') creates a Boolean mask identifying strings containing York.
Question 11 of 60 · Matching · Easy
In a regular expression, what does \d match?
Not quite. Try another option.
Answer: A digit
The regular-expression pattern \d matches one digit from 0 through 9.
Question 12 of 60 · Matching · Easy
Why might text be converted to lowercase before matching?
Not quite. Try another option.
Answer: To reduce case differences
Converting both values to lowercase allows text such as Python and PYTHON to match.
Question 13 of 60 · Matching · Easy
Which pandas function combines two DataFrames by matching values in a shared key column?
Not quite. Try another option.
Answer: pd.merge()
pd.merge() joins DataFrames by matching values in one or more key columns.
Question 14 of 60 · Matching · Easy
What is an exact match?
Not quite. Try another option.
Answer: Two values that are identical
An exact match occurs when the compared values are identical according to the comparison being used.
Question 15 of 60 · Formatting · Easy
Which string method removes leading and trailing whitespace?
Not quite. Try another option.
Answer: strip()
strip() removes whitespace from both the beginning and end of a string.
Question 16 of 60 · Formatting · Easy
Which string method changes data cleanup to Data Cleanup?
Not quite. Try another option.
Answer: title()
title() capitalizes the first letter of each word.
Question 17 of 60 · Formatting · Easy
Which function converts a pandas column to datetime values?
Not quite. Try another option.
Answer: pd.to_datetime()
pd.to_datetime() parses supported date representations into pandas datetime values.
Question 18 of 60 · Formatting · Easy
What does round(3.14159, 2) return?
Not quite. Try another option.
Answer: 3.14
The second argument tells round() to keep two digits after the decimal point.
Question 19 of 60 · Formatting · Easy
Which pandas method can rename DataFrame columns?
Not quite. Try another option.
Answer: rename()
rename() changes row or column labels without changing the stored data values.
Question 20 of 60 · Formatting · Easy
Which Python feature inserts a variable directly into a formatted string?
Not quite. Try another option.
Answer: An f-string
An f-string uses an f prefix and braces, such as f'Name: {name}', to insert values.
Question 21 of 60 · Investigation · Medium
A pandas DataFrame df contains missing values represented by both None and NaN. Which expression returns the number of missing values in each column?
Not quite. Try another option.
Answer: df.isna().sum()
isna() marks each missing value as True, and sum() counts those values column by column.
Question 22 of 60 · Investigation · Medium
A column named age was imported with the object data type. Which command is most useful for examining the Python types of its individual values?
Not quite. Try another option.
Answer: df["age"].map(type).value_counts()
map(type) obtains the type of each value, while value_counts() summarizes how often each type occurs.
Question 23 of 60 · Investigation · Medium
Which pandas expression identifies every row that belongs to a duplicated customer_id group, including the first occurrence?
Not quite. Try another option.
Answer: df.duplicated("customer_id", keep=False)
Setting keep=False marks all occurrences of every duplicated identifier as True.
Question 24 of 60 · Investigation · Medium
The values in df["status"] should be Open, Closed, or Pending. Which expression most directly reveals unexpected spellings and their frequencies?
Not quite. Try another option.
Answer: df["status"].value_counts(dropna=False)
value_counts(dropna=False) lists each distinct value, including missing values, together with its frequency.
Question 25 of 60 · Investigation · Medium
For the sorted values [10, 12, 13, 15, 16, 18, 40], suppose , , and the IQR rule uses . Which value is flagged as an upper outlier?
Not quite. Try another option.
Answer: 40
The upper boundary is . Therefore, 40 lies above the boundary.
Question 26 of 60 · Investigation · Medium
A DataFrame has 1,000 rows, but df["email"].count() returns 940. What does this establish?
Not quite. Try another option.
Answer: The column has 60 missing entries
count() excludes missing values, so entries are missing.
Question 27 of 60 · Investigation · Medium
Which call best summarizes numerical columns with count, mean, standard deviation, quartiles, minimum, and maximum?
Not quite. Try another option.
Answer: df.describe()
describe() computes the standard descriptive statistics for numerical columns by default.
Question 28 of 60 · Matching · Medium
Which regular expression matches a string containing exactly five digits and no other characters?
Not quite. Try another option.
Answer: r"^\d{5}$"
^ and $ anchor the pattern, while \d{5} requires exactly five digits.
Question 29 of 60 · Matching · Medium
Given text = "Order ID: AB-2048 completed", which function call returns the first substring matching the pattern r"[A-Z]{2}-\d{4}"?
Not quite. Try another option.
Answer: re.search(pattern, text).group()
re.search() scans the entire string and returns the first matching substring.
Question 30 of 60 · Matching · Medium
Two name columns contain " Alice Smith " and "alice smith". Which normalization makes these values equal without changing their word order?
Not quite. Try another option.
Answer: Apply str.strip().str.casefold()
strip() removes surrounding whitespace, and casefold() performs robust case-insensitive normalization.
Question 31 of 60 · Matching · Medium
A left table contains customer records, while a lookup table maps each customer_id to a region. Which merge keeps every customer even when no region matches?
%d/%m/%Y specifies a two-digit day, two-digit month, and four-digit year in that order.
Question 36 of 60 · Formatting · Medium
A price column contains values such as "$1,250.50". Which operation correctly prepares the strings for conversion with astype(float)?
Not quite. Try another option.
Answer: Remove both $ and , characters
Removing the currency symbol and thousands separator produces 1250.50, which can be converted to float.
Question 37 of 60 · Formatting · Medium
Which f-string formats value = 0.375 as the string "37.5%"?
Not quite. Try another option.
Answer: f"{value:.1%}"
The % format multiplies by 100, adds the percent sign, and .1 keeps one decimal place.
Question 38 of 60 · Formatting · Medium
A phone column should contain digits only, but values include spaces, parentheses, and hyphens. Which pandas expression removes every non-digit character?
\D matches any non-digit character, and str.replace() removes every such match.
Question 39 of 60 · Formatting · Medium
Which expression converts the integer 42 into the zero-padded string "00042"?
Not quite. Try another option.
Answer: f"{42:05d}"
d formats an integer, width 5 sets the total length, and 0 supplies leading zeros.
Question 40 of 60 · Formatting · Medium
A text column contains inconsistent internal whitespace, such as "New York" and "New York". Which expression standardizes every run of whitespace to one space and removes edge whitespace?
\s+ matches each whitespace run, replacement inserts one space, and strip() removes whitespace at the edges.
Question 41 of 60 · Investigation · Hard
Given s = pd.Series([" NA ", "", None, "n/a", "0", " NaN "]), what does clean.isna().sum() return after clean = s.astype("string").str.strip().str.casefold().replace({"": pd.NA, "na": pd.NA, "n/a": pd.NA, "nan": pd.NA})?
Not quite. Try another option.
Answer: 5
The two blank-like values, None, n/a, and NaN become missing. The string 0 remains valid.
Question 42 of 60 · Investigation · Hard
A series contains s = pd.Series([" José ", "JOSE\u0301", "Jose", "josé "]). After applying Unicode NFC normalization, trimming, and casefold(), how many rows are marked by duplicated(keep=False)?
Not quite. Try another option.
Answer: 3
The first, second, and fourth values normalize to josé. The unaccented Jose normalizes to jose.
Question 43 of 60 · Investigation · Hard
For s = pd.Series(["1", "2.0", "1e3", "NaN", "∞", "-"]), let n = pd.to_numeric(s, errors="coerce"). How many elements satisfy np.isfinite(n)?
Not quite. Try another option.
Answer: 3
1, 2.0, and 1e3 become finite numbers. The remaining three values become NaN.
Question 44 of 60 · Investigation · Hard
Using pandas' default linear quantile interpolation, which values are outliers under the rule or for the data [10, 10, 10, 100]?
Not quite. Try another option.
Answer: Only 100
, , and , giving an upper bound of . Only 100 exceeds it.
Question 45 of 60 · Investigation · Hard
A DataFrame has rows (A, 1), (A, NaN), (A, NaN), and (B, NaN) in columns group and value. What is the sum of df.duplicated(["group", "value"], keep=False)?
Not quite. Try another option.
Answer: 2
Pandas treats the two (A, NaN) rows as duplicate keys. The (B, NaN) row has a different group.
Question 46 of 60 · Investigation · Hard
Which expression most accurately counts user-perceived characters in text containing combining marks and multi-code-point emoji?
Not quite. Try another option.
Answer: len(regex.findall(r"\X", s))
The third-party regex module's \X token matches extended grapheme clusters rather than bytes or code points.
Question 47 of 60 · Matching · Hard
What is the row count of left.merge(right, on="k", how="inner") when left["k"] = [1.0, np.nan, np.nan] and right["k"] = [np.nan, 1.0]?
Not quite. Try another option.
Answer: 3 rows
Pandas matches the 1.0 keys once and, unlike SQL, matches each left null key to the right null key.
Question 48 of 60 · Matching · Hard
What happens when merging left keys [1, 2, 2] with right keys [1, 2, 2] using pd.merge(..., validate="many_to_one")?
Not quite. Try another option.
Answer: It raises pandas.errors.MergeError
A many-to-one merge requires right-side keys to be unique, but key 2 occurs twice on the right.
Question 49 of 60 · Matching · Hard
Which normalization correctly makes German "Straße" match "STRASSE" for caseless identifier comparison?
Not quite. Try another option.
Answer: Apply casefold() to both strings
casefold() performs aggressive Unicode caseless normalization, converting ß to ss; lower() does not.
Question 50 of 60 · Matching · Hard
To accept only complete identifiers such as AB-123 under the pattern [A-Z]{2}-\d{3}, which pandas expression is the safest?
Not quite. Try another option.
Answer: s.str.fullmatch(pattern, na=False)
fullmatch requires the entire value to conform and handles missing values through na=False.
Question 51 of 60 · Matching · Hard
Three source records must match three master records one-to-one using a matrix of pairwise edit costs. Which method minimizes the total cost without assigning a master record twice?
Not quite. Try another option.
Answer: Linear-sum assignment optimization
The linear-sum assignment, or Hungarian, algorithm finds a globally optimal one-to-one pairing.
Question 52 of 60 · Matching · Hard
Records and have similarity , and have similarity , and and have similarity . What risk arises if thresholded matches at are clustered using connected components?
Not quite. Try another option.
Answer: A chaining effect groups A with C
Connected components enforce transitive grouping, so the paths place dissimilar records and together.
Question 53 of 60 · Matching · Hard
A matcher declares two records equal when normalized email or normalized phone agrees. Which rule best prevents two absent values from creating a false match?
Not quite. Try another option.
Answer: Compare fields only when both values are nonmissing
Missing values provide no positive identity evidence and should not match merely because both records lack the field.
Question 54 of 60 · Matching · Hard
How many distinct normalized values remain from ["ABC", "ABC", "abc", "Abc"] after applying Unicode NFKC normalization followed by casefold()?
Not quite. Try another option.
Answer: 1
NFKC converts full-width Latin letters to ASCII, and casefold() converts uppercase letters to lowercase.
Question 55 of 60 · Formatting · Hard
What is produced by [Decimal(x).quantize(Decimal("0.01"), rounding=ROUND_HALF_EVEN) for x in ["2.345", "2.355"]]?
Not quite. Try another option.
Answer: [Decimal("2.34"), Decimal("2.36")]
Half-even rounding chooses the nearest result whose final retained digit is even.
Question 56 of 60 · Formatting · Hard
Naive timestamps 2024-11-03 01:30 and 2024-03-10 02:30 are localized to America/New_York with ambiguous="NaT" and nonexistent="shift_forward". Which result is correct?
Not quite. Try another option.
Answer: The first is NaT and the second becomes 03:00
The November time occurs twice and is marked missing; the nonexistent March time is shifted to the DST transition boundary.
Question 57 of 60 · Formatting · Hard
What tuple results from ("-42".zfill(5), "-42".rjust(5, "0"))?
Not quite. Try another option.
Answer: ("-0042", "00-42")
zfill inserts zeros after a leading sign, whereas rjust blindly inserts padding before the entire string.
Question 58 of 60 · Formatting · Hard
q = Decimal("-0.004").quantize(Decimal("0.01"), rounding=ROUND_HALF_UP) formats as -0.00. Which operation removes the negative-zero presentation without altering nonzero values?
Not quite. Try another option.
Answer: Set q = abs(q) only when q == 0
Decimal negative zero compares equal to zero, so conditionally applying abs removes its sign while preserving real negatives.
Question 59 of 60 · Formatting · Hard
Which read_csv call preserves both 0012 and the literal text NA from StringIO("id\n0012\nNA\n")?
Nearly through. Did unit 10 of ECAP776 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 10 of ECAP776 save you a night before the exam?
Then you can help keep it free for the next batch. 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.