Foundation of Data Science

Chapter 8
Exploratory Data Analysis and Visualization

Post Graduate Diploma in Data Science
Foundation of Data Science   •   Post Graduate

8. Exploratory Data Analysis and Visualization

Introduction and Context

Exploratory data analysis (EDA) is the systematic investigation of data before formal modelling, hypothesis testing, or managerial decision-making. It combines descriptive statistics, visual reasoning, domain knowledge, and critical questioning. The purpose is not merely to produce charts or calculate averages. EDA seeks to understand what the data contains, how it is structured, which patterns are credible, where anomalies occur, and what limitations may affect interpretation.

In data science, EDA occupies the space between data acquisition and analytical modelling. A dataset may contain missing values, duplicate records, inconsistent units, measurement errors, sampling bias, or relationships that are not visible in a table. Visualization provides a means of seeing structure, while statistics provide numerical summaries that support comparison and precision. Used together, they help analysts form useful questions and avoid premature conclusions.

EDA is also an important communication activity. A technical team may require distribution plots, correlation matrices, and diagnostic charts, whereas a senior manager may need a concise dashboard showing customer retention, operational risk, and performance against targets. Effective analysts therefore make two related decisions: what the data suggests and how that evidence should be communicated to a particular audience.

Learning Objectives

By the end of this chapter, students should be able to:

1. Explain the purpose, scope, and iterative nature of exploratory data analysis.

2. Calculate and interpret common measures of central tendency, dispersion, position, and association.

3. Select visualizations appropriate to distributions, relationships, comparisons, and time-based patterns.

4. Detect outliers, missingness, data-quality problems, sampling issues, and potential bias.

5. Distinguish association from causation and identify misleading interpretations.

6. Design accessible dashboards and analytical narratives for technical and managerial audiences.

7. Apply an EDA workflow to a realistic organizational problem.

8. Recognize ethical, governance, and professional responsibilities in visual data communication.

The Logic of Exploration

EDA is an iterative process rather than a single stage completed once. A typical workflow begins with a question and an understanding of how the data was generated. The analyst then inspects structure and quality, summarizes individual variables, investigates relationships, examines unusual observations, and communicates findings. New findings often lead to revised questions, further data collection, or changes in the analytical plan.

A useful distinction is between univariate, bivariate, and multivariate analysis. Univariate analysis studies one variable at a time, such as the distribution of delivery times. Bivariate analysis examines a relationship between two variables, such as advertising expenditure and sales. Multivariate analysis considers several variables together, such as the joint relationship among customer tenure, service usage, income, and churn.

Exploration should be guided by both data type and analytical purpose. Numerical variables may be continuous, such as temperature or revenue, or discrete, such as number of complaints. Categorical variables may be nominal, such as region, or ordinal, such as satisfaction levels. Dates and times possess ordered structure and often require special treatment. A chart that is suitable for nominal categories may be inappropriate for an ordinal scale, and a mean that is useful for symmetric numerical data may be misleading for highly skewed data.

A disciplined EDA process includes the following questions:

  • What does one row represent, and what does each column measure?
  • How were the observations sampled or recorded?
  • Are units, definitions, and time periods consistent?
  • Which values are missing, duplicated, impossible, or suspicious?
  • What is typical, how much variation exists, and how does the distribution behave?
  • Which relationships are strong enough to investigate further?
  • Could the apparent pattern be caused by confounding, selection bias, or measurement practices?
  • How should uncertainty and limitations be communicated?

Describing Distributions Numerically

A distribution describes how values of a variable are arranged. The mean is the arithmetic average:

\[\bar{x}=\frac{1}{n}\sum_{i=1}^{n}x_i\]

It uses every observation and is useful for many approximately symmetric distributions. However, it is sensitive to extreme values. The median is the middle value after sorting observations. It is more resistant to outliers and is often preferable for variables such as income, house prices, or waiting time. The mode is the most frequently occurring value and is particularly useful for categorical data or discrete counts.

The mean and median together provide information about shape. If the mean is substantially greater than the median, the distribution may be right-skewed; if it is lower, the distribution may be left-skewed. This is a diagnostic clue, not a complete description.

Measures of dispersion indicate how widely observations vary. The range is the maximum minus the minimum, but it depends heavily on the two most extreme observations. The variance is the average squared deviation from the mean, while the standard deviation is its square root and is expressed in the original units. For a sample, the usual variance estimator divides by \(n-1\), reflecting estimation from a sample rather than a complete population.

The interquartile range (IQR) is the difference between the third quartile and the first quartile:

\[IQR=Q_3-Q_1\]

It measures the spread of the central 50 percent of observations and is relatively robust to outliers. Quartiles divide ordered data into four sections. Percentiles generalize this idea; for example, the 90th percentile is a value at or below which approximately 90 percent of observations fall. Percentiles are useful for service-level monitoring, credit risk, examination performance, and capacity planning.

The coefficient of variation, calculated as standard deviation divided by the mean, allows relative variability to be compared across variables with different scales, provided the mean is meaningful and not close to zero. The z-score expresses how many standard deviations an observation lies above or below the mean:

\[z=\frac{x-\bar{x}}{s}\]

A z-score is not automatically evidence of an error. A rare but genuine event can have a large z-score, while a systematic measurement problem may produce ordinary-looking values.

Visual Grammar for Data Analysis

Visualization is most effective when visual encodings correspond clearly to analytical questions. Position along a common scale is generally easier to compare than area, volume, or decorative form. A chart should therefore make the intended comparison immediate and should not introduce visual effects that imply greater precision than the data supports.

Examining distributions

A histogram groups numerical values into intervals, or bins, and displays their frequencies. The choice of bin width affects interpretation: very narrow bins may emphasize random noise, while very wide bins may conceal meaningful structure. A density plot provides a smoothed representation of a distribution, but its appearance depends on the smoothing bandwidth and should not be mistaken for directly observed counts.

A box plot summarizes the median, quartiles, and selected potential outliers. It is especially useful for comparing a numerical variable across categories, such as delivery time by warehouse. A violin plot combines a box-plot summary with a density shape and can reveal multimodality, although it may be harder for nontechnical audiences to interpret.

Bar charts are appropriate for comparing counts or summary values across discrete categories. They should not be confused with histograms: bars in a histogram represent intervals of a numerical variable, whereas bars in a categorical chart represent named groups. Bar charts should generally begin at zero when the visual encoding relies on bar length.

Examining relationships

A scatter plot displays the relationship between two numerical variables. Analysts should inspect direction, form, strength, clusters, and unusual observations. A fitted line may summarize a linear trend, but it does not establish causation and may be inappropriate for a nonlinear relationship. Transparency or small multiples can help reveal overlapping observations.

For a categorical and numerical pair, grouped box plots, dot plots, or carefully designed strip plots are useful. For two categorical variables, a contingency table, grouped bar chart, or mosaic-style display may be appropriate. A heat map can summarize a matrix, such as correlations or monthly performance by region, but it requires an interpretable colour scale and clear labels.

A line chart is suited to ordered time observations. Time must be represented in chronological order, and the analyst should distinguish genuine change from seasonality, calendar effects, revisions, and changes in measurement. Connecting unrelated categories with lines can create a false impression of continuity.

Colour, scale, and annotation

Colour should encode a meaningful variable or distinguish categories. Sequential palettes suit values progressing from low to high; diverging palettes suit values around a meaningful midpoint, such as zero or a target. Excessive colours increase cognitive load. Truncated axes can exaggerate differences, although nonzero baselines may sometimes be defensible for line charts if clearly labelled and accompanied by numerical context.

Annotations should identify the event or comparison that matters, rather than decorate the chart. Titles should express the analytical message when appropriate, while subtitles, source notes, units, and definitions preserve interpretive accuracy.

Relationships, Dependence, and Uncertainty

The covariance indicates whether two variables tend to move together, but its magnitude depends on measurement units. The Pearson correlation coefficient standardizes linear association between -1 and +1. A value near +1 indicates a strong positive linear association, a value near -1 a strong negative linear association, and a value near zero little linear association. Zero correlation does not rule out a nonlinear relationship. Correlation can also be distorted by outliers, restricted ranges, or mixing several subgroups.

The Spearman rank correlation measures monotonic association using ranks and is less dependent on a linear form. It can be useful for ordinal variables or relationships affected by extreme values. Neither Pearson nor Spearman correlation demonstrates that one variable causes another.

A confounding variable influences both variables being compared and can create or conceal an association. For example, ice-cream sales and hospital visits may rise together because temperature affects both. Simpson’s paradox occurs when an aggregate relationship reverses or disappears after data is divided into relevant groups. Analysts should therefore consider stratification, subgroup comparisons, and domain knowledge before presenting an overall relationship.

EDA is not a substitute for inferential analysis. A sample statistic is an estimate and may vary across samples. Confidence intervals, sampling design, and hypothesis tests can support claims about uncertainty, but they do not correct poor measurement or biased sampling. Analysts should report the population represented by the data and avoid presenting exploratory patterns as confirmed findings without suitable validation.

Finding Anomalies Without Erasing Evidence

An anomaly is an observation that differs substantially from an expected pattern. It may be a data-entry error, a sensor malfunction, a fraudulent transaction, a rare operational event, or evidence that the assumed model is incomplete. Outlier detection methods include IQR rules, standardized scores, robust statistics such as the median absolute deviation, isolation-based algorithms, and visual inspection.

A responsible workflow does not automatically delete flagged observations. First, verify the record against its source and understand the data-generating process. Then classify the observation as an error, a valid extreme, or an unresolved case. Corrections should be documented, and the original value should be retained where governance rules permit. Sensitivity analysis can compare conclusions with and without influential observations.

Missing data also requires interpretation. Missingness may be completely unrelated to observed or unobserved values, related to observed variables, or related to the missing value itself. For instance, income may be missing more often among respondents with lower income. A missing-value indicator, a missingness heat map, or a comparison of response rates across groups can reveal structure. Mean imputation may reduce variation and distort relationships; more defensible approaches include domain-based replacement, multiple imputation, or modelling methods appropriate to the context.

Bias and the Social Meaning of Visual Evidence

Data is not automatically objective. Selection bias occurs when the observed sample differs systematically from the target population. Coverage bias arises when some members have little or no chance of inclusion. Nonresponse bias occurs when participation is related to the outcome of interest. Measurement bias results from instruments, definitions, or procedures that systematically favour certain values or groups.

EDA can reveal bias by comparing distributions and missingness across demographic, geographic, or operational groups. Analysts should examine whether a metric is equally meaningful for all groups, whether denominators are comparable, and whether aggregation conceals disparities. Rates should be accompanied by counts where possible, because a high percentage based on a very small group may be unstable or misleading.

Fair communication requires avoiding stigmatizing labels, unnecessary personal information, and visual emphasis that turns a group difference into a judgement about individuals. Sensitive attributes may be needed for fairness auditing even when they are not used in prediction. Access, retention, and disclosure should follow organizational policy and applicable privacy law.

A Practical EDA Workflow

A robust workflow can be organized as follows:

1. Define the decision context. State the operational or research question, the intended audience, and the action that evidence may inform.

2. Understand provenance. Record the source, collection process, unit of analysis, time period, definitions, and known limitations.

3. Profile the dataset. Inspect dimensions, data types, unique values, duplicates, missingness, ranges, and inconsistent formats.

4. Validate quality. Check impossible values, referential integrity, unit consistency, time ordering, and duplicate entities.

5. Summarize variables. Use appropriate statistics and distribution plots, not only averages.

6. Compare relevant groups. Examine segments defined before or justified by domain knowledge, while avoiding arbitrary subgroup hunting.

7. Investigate relationships. Use suitable plots, correlation measures, stratification, and transformations where appropriate.

8. Assess anomalies and sensitivity. Verify unusual values and test whether conclusions depend on particular records or choices.

9. Document decisions. Record cleaning rules, exclusions, transformations, chart choices, and unresolved uncertainty.

10. Communicate and validate. Present findings in a narrative, invite domain review, and distinguish exploratory results from validated conclusions.

This workflow is often implemented with Python libraries such as pandas, NumPy, Matplotlib, Seaborn, and Plotly, or with R packages such as dplyr, ggplot2, and tidyr. Notebook environments support reproducibility when code, outputs, assumptions, and data versions are preserved. Automated profiling tools can accelerate initial inspection, but they cannot replace domain interpretation or ethical judgement.

Designing Dashboards and Analytical Narratives

A dashboard is an information interface, not a collection of charts. Its design begins with decisions and users. A managerial dashboard may emphasize a small number of key performance indicators, trends, exceptions, and actions. An analyst-facing dashboard may provide filters, distributions, drill-downs, and diagnostic detail. Each additional control increases flexibility but can also increase ambiguity and the risk of selective interpretation.

A strong dashboard establishes hierarchy. The most important metric appears prominently, supporting trends are placed nearby, and detailed diagnostics are available without competing with the primary message. Metrics need definitions, units, time windows, comparison bases, and data-refresh information. Targets and thresholds should be explicit. A value without context is difficult to interpret.

Accessibility is both a design and governance requirement. Use readable type, sufficient contrast, meaningful labels, keyboard-accessible controls, and alternatives to colour-only distinctions. Red and green should not be the sole means of identifying status. Provide text or symbols, and test displays with users who have visual or cognitive accessibility needs. Avoid unnecessary animation and clutter.

An analytical narrative usually connects four elements: the question, the evidence, the interpretation, and the implication. For example: “Late deliveries increased in the northern region during the last quarter. The increase is concentrated in two facilities and coincides with a staffing change. Because the analysis is observational, the staffing change should be investigated rather than treated as proven cause. Management should review scheduling and monitor the next reporting period.” This style is more responsible than simply declaring that staffing caused lateness.

Illustrative Case Study: Exploring Customer Service Delays

Background

A fictional telecommunications provider, Northstar Connect, receives complaints about long customer-service waiting times. The operations director asks a data science team to determine whether service delays are widespread, identify operational drivers, and recommend a dashboard for weekly management review.

Situation and data

The team receives twelve months of call records. Each row represents a completed call and includes queue waiting time, call duration, service centre, customer segment, date, resolution status, and agent identifier. The team is warned that records from one centre were extracted from a newer system and may use different definitions.

Analysis

Initial profiling reveals duplicate call identifiers, missing service-centre values, and several negative waiting times. The negative values are traced to a timestamp conversion error rather than genuine performance. The team corrects the conversion rule, documents it, and preserves the original extract. A comparison of missingness shows that service-centre values are most often missing during a system migration week, so those records are not assumed to represent a random sample.

The mean waiting time is considerably higher than the median, indicating right skew. A histogram and box plot show a long upper tail. Weekly line charts reveal seasonal peaks, while box plots by centre show that the overall average is driven partly by two high-volume facilities. A scatter plot of queue length and waiting time shows a positive association, but the pattern differs by centre. After stratification, one centre has long waits even at moderate queue lengths, suggesting a local scheduling or process issue rather than a single company-wide relationship.

The team also compares resolution rates across customer segments. One segment appears to have a lower resolution rate, but its calls are longer and more complex. The analysts avoid claiming discriminatory treatment from this comparison alone. They recommend a controlled review of call types, staffing, and escalation rules, with fairness monitoring by segment.

Dashboard approach

The proposed dashboard has four layers. The top layer displays median waiting time, 90th-percentile waiting time, call volume, and resolution rate, each compared with the previous period and target. The second layer shows weekly trends. The third compares centres using distributions rather than averages alone. The final layer provides data-quality indicators, including missing records, delayed uploads, and the number of corrected timestamps.

Outcome

Management accepts the recommendation to monitor both median and 90th-percentile waiting time. The operations team begins a review of the two centres with unusual conditional patterns. Because the investigation is exploratory, no staffing policy is changed solely on the basis of correlation. A follow-up evaluation is scheduled after process changes are implemented.

Learning points

The case demonstrates that EDA is not limited to producing an attractive dashboard. It includes provenance checks, validation of definitions, distributional analysis, stratification, anomaly investigation, uncertainty, and careful translation into action. It also shows why averages alone can conceal service inequality and operational risk.

Common Errors, Risks, and Professional Responsibilities

Several mistakes recur in EDA. Analysts may begin with a favourite chart rather than a decision question; report the mean for a skewed variable; remove outliers without investigation; treat missing values as harmless; use dual axes that imply false relationships; sort categories inconsistently; or display percentages without denominators. Another danger is p-hacking through repeated subgroup exploration: a pattern found after many unplanned comparisons may be a chance result.

Dashboards can create governance risks when definitions change without notice, historical values are revised silently, or users can filter data until a preferred conclusion appears. Version control, data dictionaries, access management, audit trails, and documented refresh procedures reduce these risks. Personal and sensitive data should be minimized, masked, or aggregated where possible. Analysts must follow relevant privacy, records-management, and sector-specific requirements.

Automation and AI can assist with anomaly detection, chart recommendation, natural-language summaries, and interactive question answering. However, automated systems may reproduce sampling bias, misclassify legitimate rare events, or generate confident but unsupported narratives. Human review is essential, particularly when visual outputs influence credit, employment, healthcare, public services, or other high-impact decisions. A generated explanation should be traceable to the underlying data and calculation.

Emerging Directions

EDA is increasingly performed on streaming data, high-dimensional data, spatial records, text, images, and sensor networks. Interactive visual analytics allows users to move from aggregate patterns to individual records, while statistical process-control methods support near-real-time monitoring. Explainable machine learning tools extend EDA by showing feature effects and model errors, although these explanations also require careful interpretation.

The direction of development is not simply toward more complex graphics. It is toward reproducible, collaborative, and responsible exploration: versioned datasets, executable notebooks, governed semantic layers, accessibility-aware design, uncertainty displays, and systems that preserve the link between a claim and its evidence. The central professional skill remains the ability to ask appropriate questions and communicate what the data can—and cannot—support.

Best Practices for High-Quality EDA

  • Begin with the decision context and data-generating process.
  • Inspect distributions, not only summary averages.
  • Match chart type and visual encoding to the variable types and question.
  • Compare relevant groups and examine denominators.
  • Treat outliers and missingness as evidence requiring explanation.
  • Distinguish association, prediction, and causation.
  • Record transformations, exclusions, assumptions, and data versions.
  • Use robust summaries when distributions are skewed or contaminated by extremes.
  • Design for accessibility and provide definitions, units, sources, and dates.
  • Validate important findings with domain experts and, where possible, new data.
  • Present uncertainty and limitations alongside recommendations.

Chapter Summary

Exploratory data analysis is an iterative practice for understanding data before formal modelling or decision-making. It combines data profiling, descriptive statistics, visual displays, domain knowledge, and critical evaluation. Measures such as the mean, median, standard deviation, IQR, percentiles, and correlation describe typical values, variation, position, and association, but each has assumptions and limitations. Histograms, box plots, scatter plots, line charts, bar charts, and heat maps serve different analytical purposes.

Good EDA investigates distributions, relationships, anomalies, missingness, and possible bias. It does not automatically remove unusual records or interpret correlation as causation. Dashboards should be designed around users and decisions, with clear hierarchy, accessible encodings, definitions, targets, and data-quality information. Responsible practice includes privacy protection, reproducibility, governance, uncertainty communication, and human oversight of automated tools. The ultimate value of EDA lies in converting raw observations into defensible questions, evidence, and actions.

Key Terms

Exploratory Data Analysis: Systematic investigation of data using summaries, visualizations, and contextual reasoning.

Univariate Analysis: Analysis of one variable at a time.

Bivariate Analysis: Analysis of a relationship between two variables.

Multivariate Analysis: Analysis involving several variables simultaneously.

Mean: Arithmetic average of numerical observations.

Median: Middle ordered observation, or midpoint of the two middle observations.

Standard Deviation: Measure of typical numerical dispersion around the mean.

Interquartile Range: Difference between the third and first quartiles.

Percentile: Value below which a specified percentage of observations falls.

Skewness: Asymmetry in a probability distribution.

Outlier: Observation unusually distant from the main pattern of data.

Missingness: Absence of an expected data value.

Correlation: Standardized measure of association, commonly ranging from -1 to +1.

Confounding: Distortion of an apparent relationship by a variable related to both variables of interest.

Selection Bias: Systematic difference between the observed sample and the target population.

Histogram: Plot showing frequencies across intervals of a numerical variable.

Box Plot: Visual summary based on quartiles, median, spread, and potential outliers.

Dashboard: Interactive or static display that organizes metrics and visual evidence for monitoring or decisions.

Data Provenance: Record of a dataset’s origin, collection, transformation, and ownership.

Analytical Narrative: Structured explanation linking a question, evidence, interpretation, and implication.

Review Questions

Short Answer Questions

1. Why should the median often accompany the mean when analysing waiting times or income?

2. Distinguish a histogram from a categorical bar chart.

3. What does a scatter plot help an analyst investigate?

4. Why is an outlier not automatically a data error?

5. State two accessibility requirements for a dashboard.

Long Answer Questions

1. Explain a complete EDA workflow from defining the decision context to communicating validated findings.

2. Discuss how mean, median, standard deviation, IQR, and percentiles contribute different information about a distribution.

3. Compare appropriate visualizations for distributions, categorical comparisons, relationships, and time series.

4. Explain how missing data, selection bias, and measurement bias can affect an EDA conclusion.

5. Discuss why correlation does not establish causation, using confounding and subgroup analysis in your explanation.

Analytical / Application Questions

1. A retailer reports that average delivery time improved, but the median remained unchanged and the 90th percentile increased. What might this indicate, and which visualizations would you use to investigate?

2. A dashboard shows a large increase in complaint rates for a small demographic group. Identify checks needed before recommending a policy change.

3. You find a strong negative correlation between training hours and error rates across departments. Design an EDA plan to determine whether the relationship may be confounded by employee experience or task complexity.

22. Multiple Choice Questions with Answers

Question 1

Which measure is generally most resistant to a small number of extreme values?

A. Mean

B. Median

C. Variance

D. Range

Correct Answer: B. Median

Question 2

A histogram is most appropriate for showing:

A. The relationship between two categorical variables

B. The distribution of a numerical variable

C. A chronological sequence of unrelated categories

D. Only the largest value in each group

Correct Answer: B. The distribution of a numerical variable

Question 3

A strong correlation between two variables should be interpreted as:

A. Proof that one variable causes the other

B. Evidence of association requiring further investigation

C. Evidence that both variables are measured without error

D. Proof that no confounding variable exists

Correct Answer: B. Evidence of association requiring further investigation

Question 4

Which visualization is particularly useful for comparing the distribution of waiting times across service centres?

A. Grouped box plot

B. Pie chart with 3D effects

C. Unordered text list

D. Single total KPI

Correct Answer: A. Grouped box plot

Question 5

An analyst finds a negative transaction amount. The most responsible first action is to:

A. Delete the record immediately

B. Replace it with the mean

C. Investigate its source and meaning

D. Treat it as proof of fraud

Correct Answer: C. Investigate its source and meaning

Question 6

If the mean is substantially higher than the median, the distribution may be:

A. Right-skewed

B. Perfectly symmetric

C. Left-skewed

D. Categorical

Correct Answer: A. Right-skewed

Question 7

Why should percentages on a dashboard often be accompanied by counts?

A. Counts eliminate all sampling bias

B. Percentages cannot be calculated without counts

C. A percentage based on a small group may be unstable or misleading

D. Counts make correlation causal

Correct Answer: C. A percentage based on a small group may be unstable or misleading

Question 8

Which statement best describes a confounding variable?

A. A variable that is always missing

B. A variable related to both variables in an observed association

C. A variable with no variation

D. A variable used only for dashboard colour

Correct Answer: B. A variable related to both variables in an observed association

Question 9

Which dashboard design choice best supports accessibility?

A. Use colour alone to indicate status

B. Use low-contrast text to reduce visual weight

C. Provide labels or symbols in addition to colour

D. Remove units to simplify the display

Correct Answer: C. Provide labels or symbols in addition to colour

Question 10

In the case study, why did the analysts examine both median and 90th-percentile waiting time?

A. To ignore unusually long waits

B. To understand typical performance and the upper-tail service risk

C. To prove staffing caused delays

D. To replace all quality checks

Correct Answer: B. To understand typical performance and the upper-tail service risk

Foundation of Data Science
Chapter 8 of 14