Data Science with Python Certification Data Science with Python Exploratory Data Analysis 4 — Questions and Answers
Question 1: Which pandas method is used to compute pairwise correlations between all numeric columns of a DataFrame?
- df.cov()
- df.corr() (Correct answer)
- df.dot()
- df.corrwith()
Correct answer: df.corr()
df.corr() computes pairwise Pearson (or other) correlation coefficients between all numeric columns and returns a correlation matrix.
Question 2: In a heatmap created with seaborn's sns.heatmap(), what does the annot=True parameter do?
- Adds axis labels automatically
- Annotates each cell with its numeric value (Correct answer)
- Highlights cells above a threshold
- Adds a title to the heatmap
Correct answer: Annotates each cell with its numeric value
annot=True prints the data value inside each cell of the heatmap for easy reading.
Question 3: What is the purpose of using pd.cut() during EDA?
- To drop rows outside a specified range
- To bin a continuous variable into discrete intervals (Correct answer)
- To filter columns based on data type
- To remove duplicate values from a Series
Correct answer: To bin a continuous variable into discrete intervals
pd.cut() segments and sorts data values into discrete bins, converting a continuous variable into an ordinal categorical one.
Question 4: Which of the following correctly identifies a bimodal distribution in a histogram?
- A single tall peak near the center
- Two distinct peaks in the frequency distribution (Correct answer)
- A long tail extending to the right
- A uniform flat distribution across all bins
Correct answer: Two distinct peaks in the frequency distribution
A bimodal distribution has two local maxima (peaks), suggesting the data may come from two different subpopulations.
Question 5: When using matplotlib's plt.subplots(2, 3), what is the shape of the returned axes object?
- A flat list of 6 Axes objects
- A 2D NumPy array of shape (2, 3) (Correct answer)
- A single Axes object
- A tuple of (figure, axes_list)
Correct answer: A 2D NumPy array of shape (2, 3)
plt.subplots(nrows, ncols) returns a Figure and a 2D array of Axes objects with shape (nrows, ncols).
Question 6: What does df.pivot_table(values='sales', index='region', columns='quarter', aggfunc='sum') produce?
- A long-format DataFrame with one row per combination
- A cross-tabulation showing total sales per region per quarter (Correct answer)
- A Series of total sales grouped by region only
- A heatmap of the sales data
Correct answer: A cross-tabulation showing total sales per region per quarter
pivot_table() creates a 2D summary table where rows are regions, columns are quarters, and cells contain summed sales values.
Question 7: What does a scatter plot with a visible funnel shape (variance increasing with the x-variable) indicate?
- A strong negative correlation
- Heteroscedasticity — non-constant variance in the residuals (Correct answer)
- A perfect linear relationship
- Multicollinearity between variables
Correct answer: Heteroscedasticity — non-constant variance in the residuals
A funnel-shaped scatter plot reveals heteroscedasticity, where the spread of values changes across the range of the predictor.
Which pandas method is used to compute pairwise correlations between all numeric columns of a DataFrame?