Question 1 of 60 · Introduction to pandas · Easy
What is pandas mainly used for in Python?
A
Web page styling and layout
B
Data manipulation and analysis
C
Operating system development
D
Computer network configuration
Not quite. Try another option.
Answer: Data manipulation and analysis
pandas provides tools for organizing, manipulating, and analyzing structured data.
Question 2 of 60 · Introduction to pandas · Easy
Which statement commonly imports pandas using its standard alias?
A
using pandas as py
B
include pandas as pd
C
import pandas as pd
D
import pandas as py
Not quite. Try another option.
Answer: import pandas as pd
pd is the standard alias commonly used when importing pandas.
Question 3 of 60 · Series · Easy
What is a pandas Series?
A
A function for reading files
B
A collection of Python modules
C
A two-dimensional labeled table
D
A one-dimensional labeled array
Not quite. Try another option.
Answer: A one-dimensional labeled array
A Series stores a one-dimensional sequence of values with associated index labels.
Question 4 of 60 · Series · Easy
Which expression creates a pandas Series from a Python list?
A
pd.sort_values([10, 20, 30])
B
pd.Series([10, 20, 30])
C
pd.read_csv([10, 20, 30])
D
pd.DataFrame([10, 20, 30])
Not quite. Try another option.
Answer: pd.Series([10, 20, 30])
pd.Series() creates a Series from a list or another supported data source.
Question 5 of 60 · Series · Easy
What does the index of a pandas Series contain?
A
Formulas for the Series values
B
Labels for the Series values
C
File paths for stored values
D
Data types for all columns
Not quite. Try another option.
Answer: Labels for the Series values
The index provides a label for each value stored in the Series.
Question 6 of 60 · DataFrame · Easy
What is a pandas DataFrame?
A
A Python loop structure
B
A one-dimensional labeled array
C
A text-file compression format
D
A two-dimensional labeled table
Not quite. Try another option.
Answer: A two-dimensional labeled table
A DataFrame organizes data into labeled rows and columns.
Question 7 of 60 · DataFrame · Easy
In a DataFrame, what do columns usually represent?
A
Different variables or attributes
B
Different Python environments
C
Different program execution loops
D
Different file storage locations
Not quite. Try another option.
Answer: Different variables or attributes
Each DataFrame column generally represents a variable, feature, or attribute.
Question 8 of 60 · DataFrame · Easy
Which expression creates a DataFrame from a dictionary named data?
A
pd.DataFrame(data)
B
pd.TableSeries(data)
C
pd.SeriesFrame(data)
D
pd.readFrame(data)
Not quite. Try another option.
Answer: pd.DataFrame(data)
pd.DataFrame(data) converts a suitable dictionary into a DataFrame.
Question 9 of 60 · DataFrame · Easy
What does the shape attribute of a DataFrame return?
A
The minimum and maximum values
B
The names of rows and columns
C
The first and last records
D
The number of rows and columns
Not quite. Try another option.
Answer: The number of rows and columns
shape returns a tuple containing the DataFrame's row count and column count.
Question 10 of 60 · DataFrame · Easy
By default, what does df.head() display?
A
The last five columns
B
The first five rows
C
The first five columns
D
The last five rows
Not quite. Try another option.
Answer: The first five rows
df.head() displays the first five rows unless another number is provided.
Question 11 of 60 · Sorting · Easy
Which DataFrame method sorts rows according to the values in a column?
A
sort_index()
B
value_counts()
C
sort_values()
D
reset_index()
Not quite. Try another option.
Answer: sort_values()
sort_values() arranges rows based on the values in one or more columns.
Question 12 of 60 · Sorting · Easy
Which argument sorts DataFrame values in descending order?
A
descending=False
B
ascending=True
C
reverse=False
D
ascending=False
Not quite. Try another option.
Answer: ascending=False
Setting ascending=False arranges values from highest to lowest.
Question 13 of 60 · Sorting · Easy
Which method sorts a DataFrame according to its index labels?
A
sort_index()
B
sort_values()
C
set_index()
D
drop_index()
Not quite. Try another option.
Answer: sort_index()
sort_index() arranges the rows or columns according to their index labels.
Question 14 of 60 · Working with CSV files · Easy
Which pandas function reads data from a CSV file?
A
pd.load_csv()
B
pd.import_csv()
C
pd.open_csv()
D
pd.read_csv()
Not quite. Try another option.
Answer: pd.read_csv()
pd.read_csv() loads CSV data into a pandas DataFrame.
Question 15 of 60 · Working with CSV files · Easy
Which DataFrame method writes data to a CSV file?
A
save_csv()
B
export_csv()
C
write_csv()
D
to_csv()
Not quite. Try another option.
Answer: to_csv()
to_csv() saves the contents of a DataFrame in CSV format.
Question 16 of 60 · Working with CSV files · Easy
What is the purpose of index=False in df.to_csv("data.csv", index=False)?
A
It removes duplicate rows from the file
B
It excludes row labels from the file
C
It sorts all rows before saving
D
It excludes column names from the file
Not quite. Try another option.
Answer: It excludes row labels from the file
index=False prevents the DataFrame's row index from being written to the CSV file.
Question 17 of 60 · Operations using DataFrame · Easy
If df is a DataFrame, what does df["Age"] usually return?
A
The row named Age
B
The column named Age
C
The index named Age
D
The file named Age
Not quite. Try another option.
Answer: The column named Age
Using a column label inside brackets selects that column, usually as a Series.
Question 18 of 60 · Operations using DataFrame · Easy
Which statement creates a new column named Total by adding columns A and B?
A
df["A"] = df["Total"] + df["B"]
B
df["Total"] = df["A"] + df["B"]
C
df.add("Total", "A", "B")
D
df("Total") = df("A") + df("B")
Not quite. Try another option.
Answer: df["Total"] = df["A"] + df["B"]
Assigning the sum of two columns to df["Total"] creates or replaces the Total column.
Question 19 of 60 · Operations using DataFrame · Easy
Which DataFrame method removes rows containing missing values by default?
A
isna()
B
dropna()
C
notna()
D
fillna()
Not quite. Try another option.
Answer: dropna()
dropna() removes rows that contain missing values when used with its default settings.
Question 20 of 60 · Operations using DataFrame · Easy
What does df.describe() commonly provide for numerical columns?
A
CSV file settings
B
Sorted index labels
C
Summary statistics
D
Column data types only
Not quite. Try another option.
Answer: Summary statistics
describe() reports statistics such as count, mean, minimum, and maximum for numerical columns.
Question 21 of 60 · Introduction to pandas · Medium
Which statement correctly imports pandas using its conventional alias and creates a labeled one-dimensional object?
A
import pandas; s = pandas.Table([10, 20])
B
import pandas as pn; s = pd.DataFrame([10, 20])
C
from pandas import pd; s = pd.Array([10, 20])
D
import pandas as pd; s = pd.Series([10, 20])
Not quite. Try another option.
Answer: import pandas as pd; s = pd.Series([10, 20])
pd is the conventional pandas alias, and pd.Series() creates a labeled one-dimensional object.
Question 22 of 60 · Series · Medium
Given s1 = pd.Series([10, 20], index=['a', 'b']) and s2 = pd.Series([1, 2], index=['b', 'c']), what is the result of s1 + s2?
A
A Series containing 11 and 22 at indices a and b
B
A Series containing 10, 21, and 2 at indices a, b, and c
C
A Series containing NaN, 21, and NaN at indices a, b, and c
D
A Series containing 21 only at index b
Not quite. Try another option.
Answer: A Series containing NaN, 21, and NaN at indices a, b, and c
Series arithmetic aligns values by index. Only index b exists in both Series, so the other results are missing.
Question 23 of 60 · Series · Medium
For s = pd.Series([8, 12, 16], index=['x', 'y', 'z']), which expression returns the first two values by position?
A
s.iloc[0:2]
B
s.iloc[1:3]
C
s.loc[0:1]
D
s.loc['x':'x']
Not quite. Try another option.
Answer: s.iloc[0:2]
iloc selects by integer position, and its slice excludes the ending position, so positions 0 and 1 are returned.
Question 24 of 60 · DataFrame · Medium
What columns and number of rows are produced by pd.DataFrame({'name': ['Ana', 'Bo'], 'score': [80, 90]})?
A
Columns name and score, with 4 rows
B
One unnamed column, with 4 rows
C
Columns Ana and Bo, with 2 rows
D
Columns name and score, with 2 rows
Not quite. Try another option.
Answer: Columns name and score, with 2 rows
Dictionary keys become column names, while corresponding list elements form two rows.
Question 25 of 60 · DataFrame · Medium
A DataFrame df contains columns name, age, and city. Which expression returns a DataFrame containing only name and city?
A
df['name', 'city']
B
df[['name', 'city']]
C
df.iloc['name', 'city']
D
df.loc['name', 'city']
Not quite. Try another option.
Answer: df[['name', 'city']]
Passing a list of column labels inside brackets selects multiple columns and preserves the DataFrame structure.
Question 26 of 60 · Operations using DataFrame · Medium
Which expression selects rows where score is at least 70 and attempts is less than 3?
A
df[(df['score'] >= 70) | (df['attempts'] < 3)]
B
df[(df['score'] >= 70) & (df['attempts'] < 3)]
C
df[df['score'] >= 70 and df['attempts'] < 3]
D
df[df['score'] >= 70, df['attempts'] < 3]
Not quite. Try another option.
Answer: df[(df['score'] >= 70) & (df['attempts'] < 3)]
Element-wise conditions must be parenthesized and combined with & when both conditions are required.
Question 27 of 60 · Operations using DataFrame · Medium
A DataFrame has numeric columns price and quantity. Which statement creates a total column containing their row-wise products?
A
df['total'] = df[['price', 'quantity']].product()
B
df['total'] = df['price'] * df['quantity']
C
df['total'] = df[['price', 'quantity']].sum()
D
df['total'] = df['price'] + df['quantity']
Not quite. Try another option.
Answer: df['total'] = df['price'] * df['quantity']
Multiplication between two Series is performed element by element after index alignment.
Question 28 of 60 · Sorting · Medium
Which command sorts df by department in ascending order and then by salary in descending order?
A
df.sort_values(['department', 'salary'], ascending=[False, True])
B
df.sort_values(['salary', 'department'], ascending=[True, False])
C
df.sort_values(['department', 'salary'], ascending=[True, False])
D
df.sort_index(['department', 'salary'], ascending=[True, False])
Not quite. Try another option.
Answer: df.sort_values(['department', 'salary'], ascending=[True, False])
sort_values accepts multiple columns and a matching list of sort directions.
Question 29 of 60 · Sorting · Medium
After filtering, a DataFrame has row labels [7, 2, 5]. Which expression sorts the rows by these labels without changing column order?
A
df.sort_values()
B
df.reset_index(drop=True)
C
df.sort_index(axis=1)
D
df.sort_index(axis=0)
Not quite. Try another option.
Answer: df.sort_index(axis=0)
Axis 0 represents rows, so sort_index(axis=0) arranges rows according to their index labels.
Question 30 of 60 · Working with CSV files · Medium
A file students.csv contains five columns. Which command reads only the name and grade columns?
A
pd.read_csv('students.csv', usecols=['name', 'grade'])
B
pd.read_csv('students.csv', columns=['name', 'grade'])
C
pd.read_csv('students.csv', index_col=['name', 'grade'])
D
pd.read_csv('students.csv', names=['name', 'grade'])
Not quite. Try another option.
Answer: pd.read_csv('students.csv', usecols=['name', 'grade'])
The usecols parameter restricts loading to the specified CSV columns.
Question 31 of 60 · Working with CSV files · Medium
The first column of sales.csv is named order_id and should become the DataFrame index. Which command does this while reading the file?
A
pd.read_csv('sales.csv', usecols='order_id')
B
pd.read_csv('sales.csv', names='order_id')
C
pd.read_csv('sales.csv', header='order_id')
D
pd.read_csv('sales.csv', index_col='order_id')
Not quite. Try another option.
Answer: pd.read_csv('sales.csv', index_col='order_id')
index_col identifies the CSV column that should be used as the DataFrame index.
Question 32 of 60 · Working with CSV files · Medium
A CSV column named date contains values such as 2026-09-10. Which command asks pandas to convert that column to date-time values during import?
A
pd.read_csv('events.csv', convert_dates=['date'])
B
pd.read_csv('events.csv', dtype=['date'])
C
pd.read_csv('events.csv', date_col=['date'])
D
pd.read_csv('events.csv', parse_dates=['date'])
Not quite. Try another option.
Answer: pd.read_csv('events.csv', parse_dates=['date'])
The parse_dates parameter requests date-time parsing for the listed columns.
Question 33 of 60 · Operations using DataFrame · Medium
For a DataFrame containing only numeric values, what does df.mean(axis=1) calculate?
A
The mean of all values as one number
B
The mean of each column
C
The mean of the index labels
D
The mean of each row
Not quite. Try another option.
Answer: The mean of each row
With axis=1, pandas performs the operation horizontally across columns for each row.
Question 34 of 60 · Operations using DataFrame · Medium
A DataFrame has columns department and salary. Which expression calculates the average salary for each department?
A
df['salary'].groupby(df.index).sum()
B
df.groupby('department')['salary'].count()
C
df.groupby('department')['salary'].mean()
D
df.groupby('salary')['department'].mean()
Not quite. Try another option.
Answer: df.groupby('department')['salary'].mean()
Rows are grouped by department, and mean() is then applied to the salary values in each group.
Question 35 of 60 · Operations using DataFrame · Medium
Which expression removes only rows where the email value is missing, regardless of missing values in other columns?
A
df.drop(columns=['email'])
B
df.dropna()
C
df.dropna(subset=['email'])
D
df.dropna(axis=1)
Not quite. Try another option.
Answer: df.dropna(subset=['email'])
The subset argument limits missing-value checks to the specified column.
Question 36 of 60 · Operations using DataFrame · Medium
Which statement replaces missing values in the score column with that column's median while leaving other columns unchanged?
A
df = df['score'].dropna(df['score'].median())
B
df['score'] = df['score'].fillna(df['score'].median())
C
df['score'] = df['score'].replace(df['score'].mean())
D
df['score'] = df.fillna(df['score'].median())
Not quite. Try another option.
Answer: df['score'] = df['score'].fillna(df['score'].median())
The column median is calculated and supplied to fillna, then the updated Series is assigned back.
Question 37 of 60 · DataFrame · Medium
Which expression renames the column old_name to new_name without renaming any index labels?
A
df.replace({'old_name': 'new_name'})
B
df.rename(index={'old_name': 'new_name'})
C
df.columns.rename({'old_name': 'new_name'})
D
df.rename(columns={'old_name': 'new_name'})
Not quite. Try another option.
Answer: df.rename(columns={'old_name': 'new_name'})
The columns mapping passed to rename changes matching column labels.
Question 38 of 60 · Operations using DataFrame · Medium
DataFrames customers and orders both contain customer_id. Which expression keeps only IDs present in both DataFrames?
A
pd.merge(customers, orders, on='customer_id', how='outer')
B
customers.join(orders, how='outer')
C
pd.merge(customers, orders, on='customer_id', how='inner')
D
pd.concat([customers, orders], axis=0)
Not quite. Try another option.
Answer: pd.merge(customers, orders, on='customer_id', how='inner')
An inner merge retains only keys that occur in both DataFrames.
Question 39 of 60 · Series · Medium
A Series colors contains ['red', 'blue', 'red', 'green', 'blue', 'red']. What does colors.value_counts() return first by default?
A
The label red with count 3
B
The label blue with count 2
C
The label red with count 1
D
The label green with count 1
Not quite. Try another option.
Answer: The label red with count 3
value_counts() counts occurrences and sorts them from highest to lowest frequency by default.
Question 40 of 60 · Operations using DataFrame · Medium
Two DataFrames jan and feb have identical columns but overlapping index labels. Which expression stacks their rows and creates a fresh sequential index?
A
pd.concat([jan, feb], axis=1, ignore_index=True)
B
jan.join(feb, axis=0, ignore_index=True)
C
pd.merge(jan, feb, how='inner', ignore_index=True)
D
pd.concat([jan, feb], axis=0, ignore_index=True)
Not quite. Try another option.
Answer: pd.concat([jan, feb], axis=0, ignore_index=True)
axis=0 stacks rows, while ignore_index=True replaces the original labels with a new sequential index.
Question 41 of 60 · Introduction to pandas · Hard
Given:
left = pd.Series([10, 20], index=["a", "b"])
right = pd.Series([1, 2], index=["b", "c"])
What is (left + right).fillna(0).to_dict()?
A
{"a": 10.0, "b": 21.0, "c": 2.0}
B
{"a": 11.0, "b": 22.0, "c": 0.0}
C
{"a": 0.0, "b": 21.0, "c": 0.0}
D
{"a": 11.0, "b": 22.0, "c": 2.0}
Not quite. Try another option.
Answer: {"a": 0.0, "b": 21.0, "c": 0.0}
pandas aligns operands by index label. Only label b occurs in both Series; unmatched labels become NaN and are then replaced by 0.
Question 42 of 60 · Series · Hard
Consider s = pd.Series([3, 1, 2], index=["x", "y", "x"]). Which statement about r = s["x"] is correct?
A
r is a Series whose values sum to 5.
B
r is the scalar 3, because the first match is selected.
C
r raises an error because index labels must be unique.
D
r is the scalar 2, because the last match is selected.
Not quite. Try another option.
Answer: r is a Series whose values sum to 5.
When an index label is duplicated, label-based selection returns all matching entries as a Series. The selected values are 3 and 2.
Question 43 of 60 · Series · Hard
Given s = pd.Series([1, pd.NA, 3], dtype="Int64") and r = s * 2, which pair correctly describes r?
A
Its dtype is float64, and its values are [2.0, NaN, 6.0].
B
Its dtype is object, and its values are [2, None, 6].
C
Its dtype is Int64, and its values are [2, <NA>, 6].
D
Its dtype is Int64, and its values are [2, 0, 6].
Not quite. Try another option.
Answer: Its dtype is Int64, and its values are [2, <NA>, 6].
The nullable Int64 extension dtype preserves integer values and propagates pd.NA through arithmetic.
Question 44 of 60 · DataFrame · Hard
Given:
p = pd.Series([1, 2], index=["a", "b"])
q = pd.Series([3, 4], index=["b", "c"])
df = pd.DataFrame({"p": p, "q": q})
Which result is correct?
A
df.shape == (4, 2) and df.loc["b"].sum() == 5
B
df.shape == (3, 2) and df.loc["b"].sum() == 6
C
df.shape == (3, 2) and df.loc["b"].sum() == 5
D
df.shape == (2, 2) and df.loc["b"].sum() == 5
Not quite. Try another option.
Answer: df.shape == (3, 2) and df.loc["b"].sum() == 5
The constructor forms the union of Series indexes: a, b, and c. At b, the aligned values are 2 and 3, whose sum is 5.
Question 45 of 60 · DataFrame · Hard
Given:
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=["x", "y"])
df.loc[:, ["a", "b"]] = df.loc[:, ["b", "a"]]
What are the final columns a and b?
A
a is [1, 2], and b is [3, 4].
B
a is [1, 4], and b is [3, 2].
C
a is [3, 2], and b is [1, 4].
D
a is [3, 4], and b is [1, 2].
Not quite. Try another option.
Answer: a is [1, 2], and b is [3, 4].
DataFrame assignment through loc aligns the right-hand side by column labels. Therefore, each original column is assigned back to its matching label rather than swapped.
Question 46 of 60 · DataFrame · Hard
Given:
df = pd.DataFrame({"v": [10, 20, 30]}, index=["a", "b", "c"])
mask = pd.Series([True, False, True], index=["c", "a", "b"])
What is df.loc[mask].index.tolist()?
A
["c", "a"]
B
["b", "c"]
C
["a", "c"]
D
["c", "b"]
Not quite. Try another option.
Answer: ["b", "c"]
The Boolean Series is aligned to df by label, not position. Labels b and c map to True, and the result retains the DataFrame's original order.
Question 47 of 60 · Sorting · Hard
For the DataFrame below, what is the resulting id order after df.sort_values(["a", "b"], ascending=[True, False], na_position="first")?
df = pd.DataFrame({"id": [0, 1, 2, 3], "a": [2, 1, 1, np.nan], "b": [1, 2, 1, 0]})
A
[3, 1, 2, 0]
B
[3, 2, 1, 0]
C
[1, 2, 0, 3]
D
[0, 1, 2, 3]
Not quite. Try another option.
Answer: [3, 1, 2, 0]
NaN is placed first. The rows with a == 1 are then ordered by b descending, placing b == 2 before b == 1.
Question 48 of 60 · Sorting · Hard
Given:
df = pd.DataFrame({"id": [0, 1, 2], "a": [-2, 1, -1], "b": [1, -3, 2]})
What is the id order produced by df.sort_values(["a", "b"], key=lambda s: s.abs())?
A
[2, 0, 1]
B
[0, 2, 1]
C
[2, 1, 0]
D
[1, 2, 0]
Not quite. Try another option.
Answer: [2, 1, 0]
The key function is applied independently to each sorting column. Rows 1 and 2 tie on abs(a), so abs(b) places row 2 before row 1.
Question 49 of 60 · Sorting · Hard
A DataFrame must be sorted by one column while preserving the original relative order of rows with equal keys. Which call explicitly provides that stability?
A
df.sort_values("k", na_position="first")
B
df.sort_values("k", kind="heapsort")
C
df.sort_values("k", kind="quicksort")
D
df.sort_values("k", kind="mergesort")
Not quite. Try another option.
Answer: df.sort_values("k", kind="mergesort")
mergesort is stable, so rows whose sorting keys compare equal retain their original relative order.
Question 50 of 60 · Working with CSV files · Hard
A CSV contains:
id,value\n001,NA\n002,\n003,null\n
Which call preserves the IDs' leading zeros and reads all three value fields as literal strings rather than missing values?
A
pd.read_csv(path, dtype={"id": "string"}, keep_default_na=True)
B
pd.read_csv(path, dtype=str, na_filter=True)
C
pd.read_csv(path, dtype={"id": int, "value": "string"}, na_filter=False)
D
pd.read_csv(path, dtype={"id": "string", "value": "string"}, keep_default_na=False)
Not quite. Try another option.
Answer: pd.read_csv(path, dtype={"id": "string", "value": "string"}, keep_default_na=False)
String dtypes preserve leading zeros, while keep_default_na=False prevents NA, null, and the empty field from being interpreted using pandas' default missing-value tokens.
Question 51 of 60 · Working with CSV files · Hard
A CSV has columns in the order a,b,c. What column order is normally produced by pd.read_csv(path, usecols=["c", "a"])?
A
["c", "a"], matching the usecols list
B
["c", "b", "a"], reversing the CSV order
C
["a", "c"], matching the CSV file order
D
["a", "b", "c"], retaining every CSV column
Not quite. Try another option.
Answer: ["a", "c"], matching the CSV file order
For read_csv, the order of elements in a list-like usecols argument is ignored. Selected columns are returned in their order in the file.
Question 52 of 60 · Working with CSV files · Hard
Suppose chunks is a list of DataFrames read from one CSV using chunksize, and chunk sizes differ. Which expression computes the exact overall mean of numeric column x, ignoring missing values?
A
sum(c["x"].sum() for c in chunks) / sum(c["x"].count() for c in chunks)
B
sum(c["x"].mean() for c in chunks) / len(chunks)
C
sum(c["x"].mean() for c in chunks) / sum(c["x"].count() for c in chunks)
D
sum(c["x"].sum() for c in chunks) / len(chunks)
Not quite. Try another option.
Answer: sum(c["x"].sum() for c in chunks) / sum(c["x"].count() for c in chunks)
The global mean is the total of all nonmissing values divided by their total count. Averaging chunk means would incorrectly weight chunks equally.
Question 53 of 60 · Working with CSV files · Hard
Given the CSV text a,b\n1,10\n2,20\n3,30\n, what is the sum of column a after calling pd.read_csv(io.StringIO(text), skiprows=lambda i: i == 2)?
A
3
B
5
C
6
D
4
Not quite. Try another option.
Answer: 4
The callable receives physical row numbers starting with the header as row 0. Row 2, containing 2,20, is skipped, leaving 1 + 3 = 4.
Question 54 of 60 · Operations using DataFrame · Hard
Given:
df = pd.DataFrame({"x": [1, 2], "y": [10, 20]}, index=["a", "b"])
s = pd.Series([100, 200], index=["b", "a"])
r = df.add(s, axis="index")
What is r.loc["a"].tolist() + r.loc["b"].tolist()?
A
[201, 210, 102, 120]
B
[201, 110, 102, 220]
C
[101, 110, 202, 220]
D
[101, 210, 202, 120]
Not quite. Try another option.
Answer: [201, 210, 102, 120]
With axis="index", the Series aligns to DataFrame rows. Row a receives 200, while row b receives 100.
Question 55 of 60 · Operations using DataFrame · Hard
A left DataFrame has join keys [1, 1, 2], while the right DataFrame has unique join keys [1, 2]. What is the most restrictive validate mode that permits left.merge(right, on="key", validate=...)?
A
"one_to_one"
B
"one_to_many"
C
"many_to_many"
D
"many_to_one"
Not quite. Try another option.
Answer: "many_to_one"
Keys may repeat on the left but are unique on the right, which is precisely a many-to-one relationship.
Question 56 of 60 · Operations using DataFrame · Hard
Given:
a = pd.DataFrame({"x": [1, 2]}, index=["u", "v"])
b = pd.DataFrame({"y": [3, 4]}, index=["v", "w"])
What describes pd.concat([a, b], axis=1, join="inner")?
A
It has index ["u", "w"] and no row labeled v.
B
It has index ["v"] and values x=1, y=4 at v.
C
It has index ["v"] and values x=2, y=3 at v.
D
It has index ["u", "v", "w"] and values x=2, y=3 at v.
Not quite. Try another option.
Answer: It has index ["v"] and values x=2, y=3 at v.
Concatenation along columns aligns row indexes. An inner join retains only the common index label v.
Question 57 of 60 · Operations using DataFrame · Hard
Given:
df = pd.DataFrame({"g": ["A", "A", "B"], "x": [1, 3, 10]})
What is df[df["x"] > df.groupby("g")["x"].transform("mean")]["x"].tolist()?
A
[10]
B
[3, 10]
C
[1, 3]
D
[3]
Not quite. Try another option.
Answer: [3]
Group A has mean 2, so only 3 exceeds it. Group B has mean 10, and its sole value does not exceed that mean.
Question 58 of 60 · Operations using DataFrame · Hard
A DataFrame contains two rows with the same id and key pair but values 10 and 20. What happens when these columns are reshaped with df.pivot(index="id", columns="key", values="value")?
A
A ValueError is raised for duplicate entries.
B
The values are averaged, producing 15.
C
The last value is retained, producing 20.
D
The first value is retained, producing 10.
Not quite. Try another option.
Answer: A ValueError is raised for duplicate entries.
pivot requires each index-column pair to identify at most one value. Use pivot_table with an aggregation function when duplicates must be combined.
Question 59 of 60 · Operations using DataFrame · Hard
Given df = pd.DataFrame({"a": [1, np.nan], "b": [np.nan, np.nan]}), what does df.sum(min_count=1) contain?
A
a is 1.0, and b is NaN.
B
a is NaN, and b is NaN.
C
a is 0.0, and b is 0.0.
D
a is 1.0, and b is 0.0.
Not quite. Try another option.
Answer: a is 1.0, and b is NaN.
min_count=1 requires at least one nonmissing value. Column a meets that requirement, but the entirely missing column b does not.
Question 60 of 60 · Operations using DataFrame · Hard
Given:
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=["x", "y"])
other = pd.DataFrame({"a": [9, 8], "b": [np.nan, 7]}, index=["y", "z"])
After df.update(other), what is df.loc["y"].tolist()?
A
[2, 4]
B
[8, 7]
C
[9, 4]
D
[9, NaN]
Not quite. Try another option.
Answer: [9, 4]
update aligns on existing labels and overwrites with nonmissing values by default. Thus a at y becomes 9, while missing other.b leaves 4 unchanged.