Data Science with Python Certification Data Science with Python Exploratory Data Analysis 2 — Questions and Answers
Question 1: Which pandas method returns the number of non-null entries for each column in a DataFrame?
- df.count() (Correct answer)
- df.info()
- df.notnull().sum()
- df.shape
Correct answer: df.count()
df.count() returns the count of non-null values for each column by default.
Question 2: What does a box plot's IQR represent?
- The range of all data points
- The middle 50% of the data between Q1 and Q3 (Correct answer)
- The standard deviation of the dataset
- The distance between the min and median
Correct answer: The middle 50% of the data between Q1 and Q3
The IQR (Interquartile Range) is the span between the first quartile (Q1) and third quartile (Q3), covering the middle 50% of data.
Question 3: In pandas, what does df.duplicated().sum() compute?
- The number of columns with duplicate names
- The total number of duplicate rows in the DataFrame (Correct answer)
- The sum of all duplicated values across columns
- The index of the first duplicated row
Correct answer: The total number of duplicate rows in the DataFrame
df.duplicated() returns a boolean Series marking duplicate rows, and .sum() counts how many are True.
Question 4: Which seaborn plot is best for visualizing the relationship between two continuous variables along with their marginal distributions?
- sns.heatmap()
- sns.jointplot() (Correct answer)
- sns.violinplot()
- sns.stripplot()
Correct answer: sns.jointplot()
sns.jointplot() shows a scatter plot of two variables plus their individual marginal histograms or KDEs.
Question 5: What is the primary purpose of using df.describe() on a DataFrame containing both numeric and object columns when include='all' is passed?
- It drops all object columns before computing statistics
- It provides summary statistics for both numeric and categorical columns (Correct answer)
- It converts object columns to numeric before summarizing
- It raises a TypeError for mixed dtypes
Correct answer: It provides summary statistics for both numeric and categorical columns
Passing include='all' forces describe() to include object columns, showing count, unique, top, and freq alongside numeric stats.
Question 6: Which transformation is most appropriate to reduce right skewness in a continuous variable before EDA visualization?
- Squaring the values
- Applying a log transformation (Correct answer)
- Multiplying by a constant
- Reversing the sign of values
Correct answer: Applying a log transformation
A log transformation compresses large values and expands small ones, which reduces right (positive) skew.
Question 7: When using pandas, what does df.groupby('category')['value'].agg(['mean','std']) return?
- A single scalar value
- A DataFrame with mean and std for each category group (Correct answer)
- A list of tuples with group keys and aggregates
- A Series indexed by column names
Correct answer: A DataFrame with mean and std for each category group
agg() with a list of functions returns a DataFrame where each row is a group and each column is an aggregated statistic.
Which pandas method returns the number of non-null entries for each column in a DataFrame?