Question bank
Pick an answer to see if you're right — with an explanation.
All topicsPythonSQL / MySQLData ScienceNumPyPandasMatplotlibMachine LearningDeep LearningArtificial IntelligenceLarge Language ModelsDjangoAPIsGit & GitHubPower BIExcelStatistics
PandasEasy
Which method shows the first 5 rows?
adf.first()
bdf.top()
cdf.show()
ddf.head()
Explanation: `head()` defaults to 5 rows.
PandasEasy
Which argument makes `pd.read_csv` interpret 05/04/2025 as 5 April 2025?
amonthfirst=False
bdayfirst=True
cformat='US'
dparse_dates=False
Explanation: `dayfirst=True` tells the parser the day comes before the month.
PandasEasy
Select rows by label with…
aloc
biloc
cat
dix
Explanation: `loc` is label-based; `iloc` is position-based.
PandasEasy
What does `pd.read_excel('file.xlsx', sheet_name=None)` return?
aOnly the first sheet
bA list of column names
cA dict mapping sheet names to DataFrames
dThe number of sheets
Explanation: sheet_name=None reads every sheet into a dictionary keyed by sheet name.
PandasEasy
How do you count missing values per column?
adf.count_na()
bdf.missing()
cdf.isna().sum()
ddf.null()
Explanation: isna() returns booleans; sum counts True.
PandasEasy
Which method converts a wide table (one column per month) into long format?
amelt
bpivot
cunstack
dexplode
Explanation: melt turns columns into rows of (variable, value) pairs.
PandasMedium
Which merges two DataFrames on a key?
adf.join_on()
bdf.merge()
cpd.concat()
ddf.combine()
Explanation: merge performs SQL-style joins.
PandasEasy
Which dtype is best for a column with only 5 distinct payment modes repeated across millions of rows?
aobject
bfloat64
cstring
dcategory
Explanation: category stores each distinct value once plus compact integer codes.
PandasMedium
What does `df.groupby('city')['sales'].sum()` return?
aA Series indexed by city
bA DataFrame
cA list
dA dict
Explanation: Selecting one column after groupby gives a Series.
PandasMedium
What does this code return?
s = df.set_index("date")["amount"]
s.resample("ME").sum()
aTotal amount for each calendar month, labelled by month end
bThe mean amount per week
cThe row with the largest amount
dA TypeError because ME is invalid
Explanation: resample('ME') groups a DatetimeIndex into month-end bins; sum totals each month.
PandasEasy
Which attribute gives the number of rows and columns as a tuple?
adf.size
bdf.shape
cdf.length
ddf.count()
Explanation: `df.shape` returns (rows, columns); `df.size` is the total number of cells.
PandasMedium
`df.pivot(index='branch', columns='month', values='sales')` raises `ValueError: Index contains duplicate entries`. What is the fix?
aUse df.melt instead
bUse pd.pivot_table with an aggfunc such as 'sum'
cSort the DataFrame first
dConvert month to category
Explanation: pivot needs unique pairs; pivot_table aggregates duplicates.
PandasMedium
What does `top` contain?
top = df.sort_values('sales', ascending=False).head(3)
aThe 3 rows with the smallest sales
bThe first 3 rows of the original order
cThe 3 rows with the largest sales
dA Series of 3 sales values
Explanation: ascending=False puts the largest sales first, so head(3) takes the top three rows.
PandasMedium
Why does `df.to_csv('out.csv')` often produce an `Unnamed: 0` column when read back?
aCSV cannot store integers
bThe encoding is wrong
cThe index was written as a column; use index=False
dpandas adds a checksum column
Explanation: By default the index is saved, and it reappears as an unnamed column on reading.
PandasMedium
By default, which columns does `df.describe()` summarise?
aEvery column
bOnly object columns
cOnly the index
dOnly the numeric columns
Explanation: describe() reports count, mean, std and quartiles for numeric columns; pass include='all' to cover the rest.