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 5 MCQsHandling Data with Pandas; Data Visualisation with Matplotlib
Pandas is a Python library designed for data manipulation, cleaning, and analysis, providing structures like Series and DataFrame.
Question 2 of 60 · introduction to pandas · Easy
Which is the conventional way to import the Pandas library?
Not quite. Try another option.
Answer: import pandas as pd
By convention, Pandas is imported using import pandas as pd, giving it the short alias pd.
Question 3 of 60 · introduction to pandas · Easy
Pandas is built on top of which numerical computing library?
Not quite. Try another option.
Answer: NumPy
Pandas is built on top of NumPy, using its efficient array operations under the hood.
Question 4 of 60 · series · Easy
A Pandas Series is best described as a:
Not quite. Try another option.
Answer: One-dimensional labeled array
A Series is a one-dimensional labeled array capable of holding data of any type, with an associated index.
Question 5 of 60 · series · Easy
Which function is used to create a Pandas Series?
Not quite. Try another option.
Answer: pd.Series()
The pd.Series() constructor (with a capital S) creates a Series object.
Question 6 of 60 · series · Easy
What is the default index for a Series created from a list of 4 elements?
Not quite. Try another option.
Answer: Integers 0, 1, 2, 3
If no index is specified, Pandas assigns a default integer index starting from 0.
Question 7 of 60 · dataframe · Easy
A Pandas DataFrame is a:
Not quite. Try another option.
Answer: Two-dimensional labeled data structure
A DataFrame is a two-dimensional, size-mutable, tabular data structure with labeled rows and columns.
Question 8 of 60 · dataframe · Easy
Which method displays the first 5 rows of a DataFrame df by default?
Not quite. Try another option.
Answer: df.head()
df.head() returns the first 5 rows of a DataFrame by default; you can pass a number to change the count.
Question 9 of 60 · dataframe · Easy
Which attribute gives the number of rows and columns of a DataFrame as a tuple?
Not quite. Try another option.
Answer: df.shape
df.shape returns a tuple (rows, columns) describing the dimensions of the DataFrame.
Question 10 of 60 · working with csv files · Easy
Which Pandas function reads data from a CSV file into a DataFrame?
Not quite. Try another option.
Answer: pd.read_csv()
pd.read_csv() loads data from a CSV file and returns it as a DataFrame.
Question 11 of 60 · working with csv files · Easy
Which method writes a DataFrame df to a CSV file?
Not quite. Try another option.
Answer: df.to_csv()
df.to_csv('file.csv') saves the DataFrame contents to a CSV file.
Question 12 of 60 · working with csv files · Easy
What does CSV stand for?
Not quite. Try another option.
Answer: Comma-Separated Values
CSV stands for Comma-Separated Values, a plain-text format where fields are separated by commas.
Question 13 of 60 · operations using dataframes · Easy
Which method provides summary statistics like mean, min, and max for numeric columns?
Not quite. Try another option.
Answer: df.describe()
df.describe() generates descriptive statistics such as count, mean, standard deviation, min, and max.
Question 14 of 60 · operations using dataframes · Easy
How do you select a single column named age from a DataFrame df?
Not quite. Try another option.
Answer: df['age']
You can access a column using bracket notation df['age'], which returns that column as a Series.
Question 15 of 60 · operations using dataframes · Easy
Which method is used to remove rows containing missing (NaN) values?
Not quite. Try another option.
Answer: df.dropna()
df.dropna() removes rows (or columns) that contain missing values.
Question 16 of 60 · line plots · Easy
Which Matplotlib function is used to create a line plot?
Not quite. Try another option.
Answer: plt.plot()
plt.plot() is the standard Matplotlib function for creating line plots by default.
Question 17 of 60 · multiple subplots in one figure · Easy
Which function creates a figure with multiple subplots at once?
Not quite. Try another option.
Answer: plt.subplots()
plt.subplots() creates a figure and a set of subplots (axes) in a single call, e.g. fig, ax = plt.subplots(2, 2).
Question 18 of 60 · histograms · Easy
A histogram is mainly used to show the:
Not quite. Try another option.
Answer: Distribution of a numeric variable
A histogram displays the frequency distribution of a continuous numeric variable by grouping values into bins.
Question 19 of 60 · bar charts · Easy
Which Matplotlib function creates a vertical bar chart?
Not quite. Try another option.
Answer: plt.bar()
plt.bar() creates a vertical bar chart, while plt.barh() creates a horizontal one.
Question 20 of 60 · pie charts · Easy
A pie chart is best suited for showing:
Not quite. Try another option.
Answer: Proportions of a whole
A pie chart represents parts of a whole as slices, making it ideal for showing proportions or percentages.
Question 21 of 60 · introduction to pandas · Medium
You import pandas using import pandas as pd. Which statement correctly describes why pandas is preferred over plain Python lists for tabular data analysis?
Not quite. Try another option.
Answer: It provides labeled, aligned data structures with vectorized operations
Pandas offers Series and DataFrame with axis labels and automatic alignment, plus vectorized operations that avoid slow Python loops. It is built on top of NumPy, not a replacement for it.
Question 22 of 60 · series · Medium
Given s = pd.Series([10, 20, 30], index=['a', 'b', 'c']), what does s['b'] return?
Not quite. Try another option.
Answer: 20
Label-based indexing with s['b'] returns the value associated with the label 'b', which is 20.
Question 23 of 60 · series · Medium
What is the result of pd.Series([1, 2, 3]) + pd.Series([10, 20], index=[0, 2])?
Not quite. Try another option.
Answer: Values at index 1 become NaN due to alignment
Pandas aligns Series by index labels. Index 1 exists only in the first Series, so the sum there is NaN. Indices 0 and 2 align and are added.
Question 24 of 60 · dataframe · Medium
For a DataFrame df, which expression selects only the rows where the column age is greater than 30?
Not quite. Try another option.
Answer: df[df['age'] > 30]
Boolean masking with df['age'] > 30 produces a boolean Series, and df[...] returns the rows where the mask is True.
Question 25 of 60 · dataframe · Medium
What does df.shape return for a DataFrame with 100 rows and 5 columns?
Not quite. Try another option.
Answer: (100, 5)
df.shape returns a tuple (number_of_rows, number_of_columns), so (100, 5).
Question 26 of 60 · dataframe · Medium
Which method would you use to view the first 5 rows of a DataFrame df?
Not quite. Try another option.
Answer: df.head()
df.head() returns the first n rows (default 5). df.tail() returns the last rows. The other methods do not exist.
Question 27 of 60 · working with csv files · Medium
You have a CSV file where columns are separated by semicolons (;). Which call reads it correctly?
Not quite. Try another option.
Answer: pd.read_csv('data.csv', sep=';')
The sep parameter of pd.read_csv sets the field delimiter. Setting sep=';' handles semicolon-separated files.
Question 28 of 60 · working with csv files · Medium
You want to save a DataFrame df to a CSV file without writing the index column. Which call is correct?
Not quite. Try another option.
Answer: df.to_csv('out.csv', index=False)
df.to_csv(..., index=False) writes the DataFrame without the row index. header=False would instead drop the column names.
Question 29 of 60 · working with csv files · Medium
When reading a CSV that has no header row, which argument ensures pandas does not treat the first data row as column names?
Not quite. Try another option.
Answer: header=None
header=None tells pandas the file has no header, so it assigns default integer column labels and keeps the first row as data.
Question 30 of 60 · operations using dataframes · Medium
Given a DataFrame df with a numeric column sales, which expression computes the average of that column?
Not quite. Try another option.
Answer: df['sales'].mean()
df['sales'].mean() calls the Series mean() method to compute the arithmetic average. Pandas has no average() Series method.
Question 31 of 60 · operations using dataframes · Medium
What does df.groupby('city')['sales'].sum() produce?
Not quite. Try another option.
Answer: Total sales for each unique city
groupby('city') groups rows by city, and ['sales'].sum() aggregates the sales within each group, giving per-city totals.
Question 32 of 60 · operations using dataframes · Medium
Which method returns the count of missing (NaN) values in each column of a DataFrame df?
Not quite. Try another option.
Answer: df.isnull().sum()
df.isnull() returns a boolean DataFrame marking NaN values, and .sum() adds the True values per column, giving the missing count.
Question 33 of 60 · operations using dataframes · Medium
You want to create a new column total equal to price multiplied by quantity. Which statement is correct?
Vectorized multiplication of two columns creates a new Series, assigned to a new column via df['total'] = ....
Question 34 of 60 · line plots · Medium
Using matplotlib, which pair of calls plots y against x as a line and then displays it?
Not quite. Try another option.
Answer: plt.plot(x, y); plt.show()
plt.plot(x, y) draws a line plot with x on the horizontal axis and y on the vertical axis, and plt.show() renders the figure.
Question 35 of 60 · line plots · Medium
In plt.plot(x, y, 'r--'), what does the format string 'r--' specify?
Not quite. Try another option.
Answer: A red dashed line
In a matplotlib format string, r sets the color to red and -- sets a dashed line style.
Question 36 of 60 · multiple subplots in one figure · Medium
Which call creates a figure with a 2-row by 2-column grid of subplots?
Not quite. Try another option.
Answer: fig, ax = plt.subplots(2, 2)
plt.subplots(2, 2) returns a figure and a 2x2 array of axes objects. plt.subplot (singular) creates one axes at a position.
Question 37 of 60 · multiple subplots in one figure · Medium
After fig, axes = plt.subplots(2, 2), how do you draw on the subplot in the bottom-right corner?
Not quite. Try another option.
Answer: axes[1, 1].plot(...)
axes is a 2x2 array with zero-based indexing, so the bottom-right cell is axes[1, 1].
Question 38 of 60 · histograms · Medium
Which parameter of plt.hist(data, bins=20) controls the number of intervals the data range is divided into?
Not quite. Try another option.
Answer: bins
The bins parameter sets how many equal-width intervals the data is grouped into for the histogram.
Question 39 of 60 · histograms · Medium
A histogram is most appropriate for visualizing which of the following?
Not quite. Try another option.
Answer: The frequency distribution of a single continuous variable
Histograms group continuous data into bins and show how frequently values fall in each bin, revealing the distribution's shape.
Question 40 of 60 · bar charts · Medium
You have categories in a list cats and their counts in vals. Which call creates a vertical bar chart?
Not quite. Try another option.
Answer: plt.bar(cats, vals)
plt.bar(x, height) draws vertical bars. plt.barh would draw horizontal bars, and plt.hist is for distributions, not category counts.
Question 41 of 60 · series · Hard
Given s = pd.Series([10, 20, 30], index=['a', 'b', 'c']), what does s[0:2] return compared to s['a':'b']?
Not quite. Try another option.
Answer: s[0:2] returns elements at positions 0 and 1; s['a':'b'] returns elements 'a' and 'b' (label slicing is inclusive of endpoint)
Positional slicing (0:2) follows Python convention and is end-exclusive, returning 'a' and 'b'. Label-based slicing ('a':'b') is end-inclusive in pandas, also returning 'a' and 'b' here, but the inclusivity rule differs.
Question 42 of 60 · dataframe · Hard
For a DataFrame df, which statement correctly distinguishes df.loc[] from df.iloc[] when the index is [2, 0, 1]?
Not quite. Try another option.
Answer: df.loc[0] selects the row with index label 0; df.iloc[0] selects the first physical row (label 2)
.loc is label-based, so df.loc[0] finds the row whose index label equals 0. .iloc is integer-position based, so df.iloc[0] returns the first row regardless of its label (here labeled 2).
Question 43 of 60 · operations using dataframes · Hard
Given df1 with index ['a','b'] and df2 with index ['b','c'], what is the result of df1 + df2 for overlapping and non-overlapping labels?
Not quite. Try another option.
Answer: Rows 'a' and 'c' become NaN (no alignment match); row 'b' holds the element-wise sum
Pandas aligns on index labels before arithmetic. Matching label 'b' is summed; unmatched labels 'a' and 'c' produce NaN rather than being dropped or raising an error.
Question 44 of 60 · working with csv files · Hard
A CSV has a column of integers but some cells are empty. After pd.read_csv('data.csv'), what dtype does that column typically have and why?
Not quite. Try another option.
Answer: float64, because NaN (a float) forces the entire integer column to be upcast to float
The default int64 type cannot represent NaN. When missing values appear, pandas upcasts the column to float64 so NaN can be stored, unless a nullable Int64 dtype is explicitly requested.
Question 45 of 60 · operations using dataframes · Hard
For a numeric DataFrame df, how do df.apply(np.sum, axis=0) and df.apply(np.sum, axis=1) differ?
Not quite. Try another option.
Answer: axis=0 returns one sum per column (collapsing rows); axis=1 returns one sum per row (collapsing columns)
axis=0 applies the function down each column (across rows), yielding a value per column. axis=1 applies across columns for each row, yielding a value per row.
Question 46 of 60 · dataframe · Hard
What is the key behavioral difference between df.dropna(how='all') and df.dropna(how='any') (default)?
Not quite. Try another option.
Answer: how='all' drops a row only if every value is NaN; how='any' drops a row if at least one value is NaN
With how='any' (the default), a row is removed if it contains at least one missing value. With how='all', a row is removed only when all of its values are missing.
Question 47 of 60 · line plots · Hard
When plotting plt.plot(x, y1); plt.plot(x, y2) on the same axes without specifying colors, what happens?
Not quite. Try another option.
Answer: Matplotlib automatically assigns different colors from the default color cycle to each line
Successive plot calls on the same axes draw over each other, and Matplotlib advances through its property (color) cycle, so each line gets a distinct default color automatically.
Question 48 of 60 · multiple subplots in one figure · Hard
Using fig, ax = plt.subplots(2, 2), how should you correctly access the subplot in the bottom-right position?
Not quite. Try another option.
Answer: ax[1, 1], because ax is a 2D NumPy array of Axes indexed by [row, column]
When subplots(nrows, ncols) creates a grid with both dimensions > 1, it returns a 2D NumPy array of Axes. Zero-based indexing means the bottom-right cell of a 2×2 grid is ax[1, 1].
Question 49 of 60 · histograms · Hard
For plt.hist(data, bins=10) on data ranging from 0 to 100, what determines each bin's width and count?
Not quite. Try another option.
Answer: Width is the range divided by bins (10 units each); count is the number of data points falling in each interval
By default hist creates equal-width bins: the data range is split into 10 intervals of 10 units. Each bar's height is the frequency of values falling into that interval, not a cumulative or equal-frequency count.
Question 50 of 60 · bar charts · Hard
What is the fundamental difference between plt.bar() and plt.hist()?
Not quite. Try another option.
Answer: bar() plots one bar per categorical/discrete value you supply; hist() bins continuous data and plots frequencies of those bins
bar() draws bars for explicit category-value pairs you provide. hist() takes raw continuous data, groups it into bins, and plots how many values fall in each bin.
Question 51 of 60 · pie charts · Hard
In plt.pie(sizes, autopct='%1.1f%%'), what does autopct control and how are wedge sizes determined?
Not quite. Try another option.
Answer: autopct formats each wedge's percentage label; wedge angles are proportional to each value divided by the total
autopct is a format string that displays each slice's percentage. Pie wedges are auto-normalized: each wedge's angle equals its value divided by the sum of all values, so they always total 100%.
Question 52 of 60 · introduction to pandas · Hard
Why can a pandas Series hold heterogeneous data more flexibly than a plain NumPy array of a fixed numeric dtype?
Not quite. Try another option.
Answer: A Series can fall back to the object dtype, storing Python objects of mixed types, though at the cost of vectorized performance
When a Series contains mixed types, pandas uses the object dtype, which holds references to arbitrary Python objects. This allows heterogeneity but loses the speed of homogeneous vectorized operations.
Question 53 of 60 · operations using dataframes · Hard
Given df.groupby('cat')['val'].transform('mean'), how does its output differ from df.groupby('cat')['val'].mean()?
Not quite. Try another option.
Answer: transform returns a Series aligned to the original rows (each row gets its group mean); mean returns one aggregated value per group
.mean() aggregates, producing one row per group. .transform('mean') broadcasts the group result back to the original index shape, so every original row receives its group's mean — ideal for creating derived columns.
Question 54 of 60 · working with csv files · Hard
What is the effect of pd.read_csv('data.csv', index_col=0) versus omitting index_col?
Not quite. Try another option.
Answer: With index_col=0, the first column becomes the DataFrame index; without it, a default RangeIndex (0,1,2,...) is created and all columns are kept as data
index_col=0 designates the first column as the row index, removing it from the data columns. Without it, pandas generates an automatic integer RangeIndex and treats every column as data.
Question 55 of 60 · dataframe · Hard
Which comparison of df['col'] and df[['col']] is correct?
Not quite. Try another option.
Answer: df['col'] returns a 1D Series; df[['col']] returns a single-column DataFrame (2D)
Single brackets with a scalar key extract a Series. Passing a list of column names (even one) returns a DataFrame, preserving 2D structure — useful when downstream code expects a DataFrame.
Question 56 of 60 · multiple subplots in one figure · Hard
When fig, axes = plt.subplots(1, 3, sharey=True) is used, what does sharey=True accomplish?
Not quite. Try another option.
Answer: All three subplots share the same y-axis scale and limits, and inner y-tick labels are hidden for clarity
sharey=True links the y-axes so they use identical limits and scale, enabling fair visual comparison across subplots. Matplotlib also hides redundant inner y-tick labels.
Question 57 of 60 · series · Hard
For s = pd.Series([1, 2, 3]), why does s + pd.Series([1, 2, 3], index=[1, 2, 3]) produce NaN values?
Not quite. Try another option.
Answer: Labels are aligned before addition; only indices 1 and 2 overlap, so indices 0 and 3 yield NaN
The first Series has default index 0,1,2; the second has index 1,2,3. Pandas aligns on labels: overlapping labels 1 and 2 add, while labels 0 and 3 exist in only one Series and become NaN.
Question 58 of 60 · histograms · Hard
In plt.hist(data, bins=20, density=True), what does density=True change about the y-axis?
Not quite. Try another option.
Answer: The y-axis shows probability density so the total area under the bars equals 1, rather than raw counts
With density=True, bar heights are normalized so that the integral (total area) over all bins equals 1, turning the histogram into an estimate of the probability density function instead of frequencies.
Question 59 of 60 · line plots · Hard
Given time-series x values that are unsorted, what visual artifact does plt.plot(x, y) produce and why?
Not quite. Try another option.
Answer: The line zig-zags back and forth because plot connects points in the order given, not in sorted x-order
plot draws straight segments between consecutive data points in their given sequence. If x is unsorted, the line reverses direction, creating a tangled zig-zag. Sorting by x first fixes this.
Question 60 of 60 · operations using dataframes · Hard
What does df.merge(other, on='key', how='outer') produce compared to how='inner'?
Not quite. Try another option.
Answer: outer keeps all keys from both frames (filling unmatched sides with NaN); inner keeps only keys present in both
An outer join is the union of keys, inserting NaN where a side lacks a match. An inner join is the intersection, retaining only keys that appear in both DataFrames.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of ECE181 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of ECE181 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.