Data Science with Python Exploratory Data Analysis Questions and Answers — Questions and Answers
Question 1: A data scientist wants to get a quick overview of the central tendency, dispersion, and shape of the distribution of all numerical columns in a pandas DataFrame called `df_numeric`. Which of the following methods is most direct and conventional for this task?
- df_numeric.info()
- df_numeric.describe() (Correct answer)
- df_numeric.mean()
- df_numeric.hist()
Correct answer: df_numeric.describe()
The `df.describe()` method is the standard way to generate descriptive statistics for a DataFrame. [4, 9, 17] It provides a summary that includes count, mean, standard deviation, min, max, and percentiles for all numerical columns, offering a comprehensive first look at the data's distribution and scale. [4, 27] `df.info()` provides data types and non-null counts, `df.mean()` only calculates the mean, and `df.hist()` creates visualizations but does not return a statistical summary table.
Question 2: When performing EDA on a DataFrame with a categorical column 'Status', which pandas method is most suitable for quickly determining the number of occurrences for each unique category?
- df['Status'].unique()
- df['Status'].count()
- df['Status'].value_counts() (Correct answer)
- df.groupby('Status').count()
Correct answer: df['Status'].value_counts()
`df['Status'].value_counts()` is specifically designed to count the occurrences of each unique value in a Series, returning a new Series with the counts in descending order. [5, 11, 20] This is extremely useful for understanding the distribution of categorical data. [5, 20] `unique()` only returns the unique values without counts. `count()` returns the total number of non-null entries. `groupby().count()` is more verbose and, while it can achieve a similar result, `value_counts()` is the more direct and idiomatic method for this specific task.
Question 3: A data analyst is investigating the relationship between two continuous variables, 'engine_size' and 'co2_emissions'. Which type of plot is the most appropriate and standard choice for visualizing this relationship?
- Histogram
- Box Plot
- Bar Chart
- Scatter Plot (Correct answer)
Correct answer: Scatter Plot
A scatter plot is the standard and most effective visualization for examining the relationship and joint distribution between two continuous numerical variables. [3, 8] Each point on the plot represents an observation, allowing the analyst to identify trends, patterns, and correlations. Histograms visualize the distribution of a single variable. [1] Box plots are better for comparing a continuous variable across different categories. [2] Bar charts are used for comparing quantities across discrete categories.
Question 4: You are analyzing a correlation heatmap generated using Seaborn to understand the relationships between numerical features in a dataset. What does a cell with a bright, dark red color and an annotation of `0.85` typically signify (using a standard 'coolwarm' or similar diverging colormap)?
- A weak negative correlation between the two variables.
- No correlation between the two variables.
- A strong positive correlation between the two variables. (Correct answer)
- A perfect negative correlation between the two variables.
Correct answer: A strong positive correlation between the two variables.
In a standard diverging colormap like 'coolwarm' used for correlation heatmaps, warm colors (like red) represent positive correlations, while cool colors (like blue) represent negative correlations. [18] The intensity of the color indicates the strength of the correlation, and the annotated value provides the precise coefficient. A value of 0.85 is close to +1, indicating a strong positive correlation. [6, 18]
Question 5: Which of the following visualizations is most effective for summarizing the distribution of a single numerical variable by showing its median, quartiles, and specifically highlighting potential outliers?
- Line Plot
- Box Plot (Correct answer)
- Pie Chart
- Scatter Plot
Correct answer: Box Plot
A box plot (or box-and-whisker plot) is specifically designed to display the five-number summary of a dataset: minimum, first quartile (Q1), median, third quartile (Q3), and maximum. [2, 14, 33] Points that fall outside the whiskers (typically defined as 1.5 times the interquartile range beyond Q1 and Q3) are explicitly rendered as individual points, making them an excellent tool for identifying potential outliers. [2, 28, 32]
Question 6: A data scientist wants to visualize the frequency distribution of a single continuous variable, `age`, from a pandas DataFrame. Which Seaborn function is primarily used for this purpose?
- seaborn.boxplot(x=df['age'])
- seaborn.scatterplot(x=df['age'], y=df['income'])
- seaborn.histplot(data=df, x='age') (Correct answer)
- seaborn.countplot(data=df, x='age')
Correct answer: seaborn.histplot(data=df, x='age')
`seaborn.histplot` (or the older `distplot`) is the primary function for creating a histogram, which visualizes the distribution of a single continuous variable by dividing the data into bins and showing the frequency of observations in each bin. [1, 23] `boxplot` shows quartiles and outliers. `scatterplot` is for two continuous variables. [3] `countplot` is for categorical variables, not continuous ones.
A data scientist wants to get a quick overview of the central tendency, dispersion, and shape of the distribution of all numerical columns in a pandas DataFrame called `df_numeric`.
Which of the following methods is most direct and conventional for this task?