Unit 10: Data cleanup - Practice Quiz
1 Which pandas method displays the first few rows of a DataFrame?
df.head()
df.describe()
df.tail()
df.info()
2 Which DataFrame attribute returns the number of rows and columns?
df.size
df.columns
df.shape
df.index
3 Which pandas expression counts missing values in each column?
df.describe() followed by manually counting every blank cell
df.isna().sum()
df.fillna().sum()
df.dropna().sum()
4 Which method identifies duplicate rows in a pandas DataFrame?
df.duplicated()
df.unique()
df.repeated()
df.dropna()
5
What does df.info() mainly show?
6
Which method returns the distinct values in a pandas Series named colors?
colors.value()
colors.describe()
colors.unique()
colors.duplicated()
7 Which method provides summary statistics such as count, mean, and standard deviation for numeric columns?
df.head()
df.info()
df.describe()
df.columns()
8 Which operator checks whether two Python values are equal?
!=
>=
=
==
9 Which pandas method checks whether Series values appear in a given list?
astype()
isna()
isin()
sort_values()
10
Which expression finds rows where the city column contains the text York?
df['city'].str.contains('York')
df['city'].apply() with a separate database lookup for each row
df['city'].str.replace('York')
df['city'].str.len('York')
11
In a regular expression, what does \d match?
12 Why might text be converted to lowercase before matching?
13 Which pandas function combines two DataFrames by matching values in a shared key column?
pd.read_csv()
pd.to_datetime()
pd.merge()
pd.concat()
14 What is an exact match?
15 Which string method removes leading and trailing whitespace?
replace()
find()
strip()
split()
16
Which string method changes data cleanup to Data Cleanup?
upper()
capitalize()
title()
lower()
17 Which function converts a pandas column to datetime values?
pd.format_dates_and_rebuild_the_entire_dataframe()
pd.read_html()
pd.to_numeric()
pd.to_datetime()
18
What does round(3.14159, 2) return?
3.142
3.1
4.00
3.14
19 Which pandas method can rename DataFrame columns?
replace()
reindex()
rename()
reset_index()
20 Which Python feature inserts a variable directly into a formatted string?
21
A pandas DataFrame df contains missing values represented by both None and NaN. Which expression returns the number of missing values in each column?
df.isnull().any()
df.count().sum()
df.isna().count()
df.isna().sum()
22
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?
df["age"].describe(include="all")
df["age"].astype(str).count()
df["age"].map(type).value_counts()
df["age"].dtype.value_counts()
23
Which pandas expression identifies every row that belongs to a duplicated customer_id group, including the first occurrence?
df.duplicated("customer_id", keep=False)
df.drop_duplicates("customer_id").index
df.duplicated("customer_id", keep="first")
df["customer_id"].is_unique
24
The values in df["status"] should be Open, Closed, or Pending. Which expression most directly reveals unexpected spellings and their frequencies?
df["status"].value_counts(dropna=False)
df["status"].sort_values(ignore_index=True)
df["status"].describe().loc["count"]
df["status"].nunique(dropna=False)
25
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?
27
13
18
40
26
A DataFrame has 1,000 rows, but df["email"].count() returns 940. What does this establish?
27 Which call best summarizes numerical columns with count, mean, standard deviation, quartiles, minimum, and maximum?
df.describe()
df.value_counts()
df.info()
df.memory_usage()
28 Which regular expression matches a string containing exactly five digits and no other characters?
r"^\d{5}$"
r"\d{1,5}$"
r"\d{5,}"
r"^\d+$"
29
Given text = "Order ID: AB-2048 completed", which function call returns the first substring matching the pattern r"[A-Z]{2}-\d{4}"?
re.fullmatch(pattern, text).group()
re.match(pattern, text).group()
re.search(pattern, text).group()
re.split(pattern, text)[0]
30
Two name columns contain " Alice Smith " and "alice smith". Which normalization makes these values equal without changing their word order?
str.title().str.swapcase()
str.split().str.reverse()
str.strip().str.casefold()
str.upper().str.rstrip("h")
31
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?
customers.merge(regions, on="customer_id", how="cross")
customers.merge(regions, on="customer_id", how="left")
customers.merge(regions, on="customer_id", how="inner")
customers.merge(regions, on="customer_id", how="right")
32
A lookup table unexpectedly has two rows for the same product_id. What can happen when it is merged with a sales table on product_id?
33
Which expression selects rows whose code value starts with two uppercase letters followed by exactly three digits?
df["code"].str.match(r"\d{3}[A-Z]{2}")
df["code"].str.contains(r"[A-Z]\d{3}")
df["code"].str.startswith(r"[A-Z]{2}")
df["code"].str.fullmatch(r"[A-Z]{2}\d{3}")
34
You need to find approximate duplicates such as "Jon Smyth" and "John Smith". Which technique is most appropriate after basic text normalization?
35
A column contains dates such as "31/12/2025". Which conversion explicitly interprets them as day/month/year?
pd.to_numeric(df["date"], errors="coerce")
pd.to_datetime(df["date"], format="%m/%d/%Y")
df["date"].astype("datetime", format="%Y/%m/%d")
pd.to_datetime(df["date"], format="%d/%m/%Y")
36
A price column contains values such as "$1,250.50". Which operation correctly prepares the strings for conversion with astype(float)?
, with . only
$ and , characters
. and , characters
$ with . only
37
Which f-string formats value = 0.375 as the string "37.5%"?
f"{value * 10:.1%}"
f"{value:.1%}"
f"{value:%1.1f}"
f"{value:.1f}%"
38
A phone column should contain digits only, but values include spaces, parentheses, and hyphens. Which pandas expression removes every non-digit character?
df["phone"].str.strip("()-")
df["phone"].str.replace(r"\d", "", regex=True)
df["phone"].str.replace(r"\D", "", regex=True)
df["phone"].str.extract(r"\D+")
39
Which expression converts the integer 42 into the zero-padded string "00042"?
f"{42:5d}"
f"{42:05f}"
f"{42:05d}"
f"{42:.5d}"
40
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?
df["city"].str.replace(" ", "", regex=False).str.strip()
df["city"].str.replace(r"\s+", " ", regex=True).str.strip()
df["city"].str.pad(8, fillchar=" ").str.rstrip()
df["city"].str.split(" ").str.get(0).str.strip()
41
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})?
42
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)?
43
For s = pd.Series(["1", "2.0", "1e3", "NaN", "∞", "-"]), let n = pd.to_numeric(s, errors="coerce"). How many elements satisfy np.isfinite(n)?
44
Using pandas' default linear quantile interpolation, which values are outliers under the rule or for the data [10, 10, 10, 100]?
10
100
45
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)?
46 Which expression most accurately counts user-perceived characters in text containing combining marks and multi-code-point emoji?
len(unicodedata.normalize("NFC", s))
len(s.encode("utf-16")) // 2
len(regex.findall(r"\X", s))
len(s.encode("utf-8"))
47
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]?
48
What happens when merging left keys [1, 2, 2] with right keys [1, 2, 2] using pd.merge(..., validate="many_to_one")?
pandas.errors.MergeError
49
Which normalization correctly makes German "Straße" match "STRASSE" for caseless identifier comparison?
lower() to both strings
swapcase() to both strings
casefold() to both strings
capitalize() to both strings
50
To accept only complete identifiers such as AB-123 under the pattern [A-Z]{2}-\d{3}, which pandas expression is the safest?
s.str.contains(pattern, na=False)
s.str.fullmatch(pattern, na=False)
s.str.match(pattern, na=False)
s.str.findall(pattern).str.len() > 0
51 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?
52 Records and have similarity , and have similarity , and and have similarity . What risk arises if thresholded matches at are clustered using connected components?
53 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?
54
How many distinct normalized values remain from ["ABC", "ABC", "abc", "Abc"] after applying Unicode NFKC normalization followed by casefold()?
55
What is produced by [Decimal(x).quantize(Decimal("0.01"), rounding=ROUND_HALF_EVEN) for x in ["2.345", "2.355"]]?
[Decimal("2.35"), Decimal("2.35")]
[Decimal("2.34"), Decimal("2.36")]
[Decimal("2.35"), Decimal("2.36")]
[Decimal("2.34"), Decimal("2.35")]
56
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?
NaT and the second becomes 03:00
01:00 and the second is unchanged
NaT
57
What tuple results from ("-42".zfill(5), "-42".rjust(5, "0"))?
("00-42", "-0042")
("-0420", "-0042")
("00-42", "-0420")
("-0042", "00-42")
58
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?
q = abs(q) only when q == 0
q = Decimal(0) when q < 0
q = -q when q < 0
q = abs(q) for every value
59
Which read_csv call preserves both 0012 and the literal text NA from StringIO("id\n0012\nNA\n")?
pd.read_csv(buf, keep_default_na=False)
pd.read_csv(buf, na_filter=True, converters={"id": int})
pd.read_csv(buf, dtype={"id": "string"})
pd.read_csv(buf, dtype={"id": "string"}, keep_default_na=False)
60
What does pd.Timestamp("2024-01-01 00:30", tz="UTC").tz_convert("America/New_York").strftime("%Y-%m-%d") return?
"2023-12-30"
"2023-12-31"
"2024-01-02"
"2024-01-01"
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 →