Exploratory Data Analysis (EDA): Steps and Methods
Exploratory data analysis (EDA) is the first look at a dataset before any model is built. You check its structure and data types, find missing values and duplicates, summarise and plot each variable, study relationships between variables and investigate outliers, so that problems and patterns are known before modelling starts.
Exploratory data analysis is where you find out what your data actually contains, as opposed to what the data dictionary says it contains. John Tukey made the case for it in his 1977 book: look at the data with simple summaries and plots first, and let what you see suggest the questions and the models. It is step 4 of the data science workflow.
Why exploratory data analysis comes first
Summary numbers can hide a lot. In 1973 F. J. Anscombe published four small datasets, now called Anscombe’s quartet, that share the same mean of x (9), mean of y (7.50), correlation (0.816) and regression line (y = 3.00 + 0.500x). Plotted, they look nothing alike: one is a clean linear cloud, one is a curve, one is a straight line spoilt by a single outlier, and one is a vertical stack with one far point. A model fitted from the numbers alone would treat all four the same.
EDA also catches dull but costly problems early: a temperature column stored as text, a date in two formats, a sensor that reads zero whenever it is offline. Finding these after a model is in production is much more expensive.
Exploratory data analysis steps
1. Restate the question and know the data
Write down the question the data must answer and where each column comes from. For each variable, note its meaning, unit, how it is measured and how often. A column called “flow” is useless until you know whether it is m³/h or litres per minute, and whether it is instantaneous or averaged.
2. Check structure and data types
Count rows and columns, and check that each column has the right type: numbers as numbers, dates as dates, categories as categories. In pandas, df.shape, df.info() and df.head() do this in seconds. Look at the time span and sampling rate for time series, and check for duplicate rows or duplicate keys.
3. Find missing values
Count missing values per column (df.isna().sum()) and look at where they occur. Missing values that cluster in one week, one site or one machine usually point to an outage or a logging fault, not random loss. Decide whether to drop, fill or flag them, but only after you understand why they are missing. Also watch for disguised missing values such as 0, 9999 or “N/A” typed as text.
4. Look at one variable at a time
This is univariate analysis. For numeric columns, compute the count, mean, standard deviation, minimum, quartiles and maximum (df.describe()), then draw a histogram and a box plot. Ask:
- Is the distribution symmetric, skewed or split into two peaks (which can mean two operating modes)?
- Is the mean far from the median? That points to skew or outliers.
- Are the minimum and maximum physically possible?
For categorical columns, count each level (value_counts()). Look for spelling variants of the same category and for rare levels.
5. Study relationships between variables
This is bivariate and multivariate analysis. Use scatter plots for two numeric variables, box plots of a numeric variable grouped by a category, and line plots against time. A correlation matrix shown as a heat map gives a quick overview of linear relationships.
The Pearson correlation coefficient r measures the strength of a linear relationship, from minus 1 to plus 1. It does not detect curved relationships, and correlation alone never proves cause. Anscombe’s quartet shows why a scatter plot should always sit beside the number.
6. Investigate outliers and record findings
Tukey’s box plot rule flags a value as a possible outlier when it lies more than 1.5 times the interquartile range (IQR) beyond the quartiles. Check each flagged value before deciding anything: look at the logbook, the sensor and the units. Finish by writing short notes: data problems found, decisions made, patterns seen and new hypotheses. These notes feed feature engineering and model choice.
Key formulas for exploratory data analysis
| Quantity | Formula | Symbols and units |
|---|---|---|
| Sample mean | x̄ = Σx ÷ n | x = values, n = number of values; same unit as x |
| Sample standard deviation | s = √[Σ(x − x̄)² ÷ (n − 1)] | same unit as x |
| Interquartile range | IQR = Q3 − Q1 | Q1, Q3 = first and third quartiles; same unit as x |
| Outlier fences | Q1 − 1.5 × IQR and Q3 + 1.5 × IQR | values outside are possible outliers |
| z-score | z = (x − x̄) ÷ s | dimensionless |
| Pearson correlation | r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² Σ(y − ȳ)²] | dimensionless, from −1 to +1 |
The IQR fences in symbols:
Worked example: finding an outlier in pump vibration data
- Given
- Ten daily vibration velocity readings from one pump, in mm/s: 2.1, 2.3, 2.4, 2.4, 2.5, 2.6, 2.7, 2.8, 3.0, 6.9.
- Find
- The median, quartiles, IQR fences and any outlier; compare the mean and median; check the z-score of the largest value.
- Assumptions
- Quartiles by linear interpolation, the default in NumPy and pandas. Sample standard deviation with n − 1.
- Solution
- Median = (2.5 + 2.6) ÷ 2 = 2.55 mm/s
Q1 = 2.4 mm/s, Q3 = 2.775 mm/s, IQR = 2.775 − 2.4 = 0.375 mm/s
Lower fence = 2.4 − 1.5 × 0.375 = 1.84 mm/s
Upper fence = 2.775 + 1.5 × 0.375 = 3.34 mm/s
6.9 is above 3.34, so it is flagged; all other values lie inside the fences.
Mean = 29.7 ÷ 10 = 2.97 mm/s; without 6.9 the mean is 22.8 ÷ 9 = 2.53 mm/s
s = 1.40 mm/s, so z for 6.9 = (6.9 − 2.97) ÷ 1.40 = 2.80 - Answer
- 6.9 mm/s is an outlier by the IQR rule. The mean (2.97 mm/s) is pulled well above the median (2.55 mm/s) by this one reading, yet its z-score is only 2.80, below a common cut-off of 3.
- Limitations
- The outlier inflates the standard deviation it is judged against, which is why the z-score misses it here; the IQR rule is more robust for small samples. Whether 6.9 mm/s is a fault or a real change in the pump needs an engineering check.
Common EDA plots and when to use them
| Plot | Shows | Use for |
|---|---|---|
| Histogram | Shape of one numeric variable | Skew, peaks, gaps, impossible values |
| Box plot | Median, quartiles and outliers | Comparing groups, flagging outliers |
| Bar chart of counts | Frequency of each category | Rare or misspelt categories |
| Scatter plot | Two numeric variables | Linear and curved relationships, clusters |
| Line plot over time | Trend, seasonality, steps | Sensor drift, outages, operating changes |
| Correlation heat map | r for every pair | Quick screen of linear links |
Common mistakes in exploratory data analysis
- Trusting summary statistics without plots. Anscombe’s quartet is the classic warning.
- Deleting outliers automatically. In maintenance data, the outlier is often the early sign of the failure you want to predict.
- Exploring the test set. Decisions made after looking at test data leak information and give an over-optimistic score; see overfitting and underfitting.
- Ignoring time. Shuffled sensor data hides drift, outages and changes of operating mode.
- Not writing anything down. Unrecorded cleaning choices cannot be repeated or reviewed.
EDA also tells you what kind of model is worth trying. A clear target column points to supervised learning; groups that appear in scatter plots without a label suggest clustering. With very large tables, work on a representative sample first, as discussed in the five Vs of big data.
Exploratory data analysis interview and viva questions
- What is the purpose of exploratory data analysis? To understand the structure, quality, distributions and relationships in a dataset before modelling, so that problems are fixed and modelling choices are based on what the data actually shows.
- What does Anscombe’s quartet demonstrate? Four datasets with the same mean, correlation and regression line look completely different when plotted, so summary statistics must always be checked with plots.
- How does the box plot rule flag outliers? A value more than 1.5 times the interquartile range below Q1 or above Q3 is flagged as a possible outlier.
- Why can a z-score test miss an outlier in a small sample? The outlier raises the mean and the standard deviation it is measured against, so its z-score shrinks; in the worked example a clear outlier scored only 2.80.
- Why should you not explore the test set? Choices made after seeing test data leak information into the model, so the test score no longer gives a fair estimate of performance on new data.
Frequently asked questions
What is the difference between EDA and data cleaning?
Data cleaning fixes known problems such as wrong types, duplicates and missing values. Exploratory data analysis is the wider job of understanding the data: it often finds the problems that cleaning then fixes, and it continues after cleaning to study distributions and relationships. In practice the two run back and forth.
Which Python tools are used for exploratory data analysis?
pandas is the usual starting point, with info, describe, isna, value_counts and corr for tables and summaries. matplotlib and seaborn draw histograms, box plots, scatter plots and heat maps. Jupyter notebooks are common because they keep code, plots and notes together.
Should outliers always be removed during EDA?
No. An outlier may be a sensor fault or a typing error, but it may also be the rare event you care about, such as a machine starting to fail. Investigate each one, record what you decided and why, and keep the raw data unchanged.
References
- J. W. Tukey, Exploratory Data Analysis, Addison-Wesley, 1977
- NIST/SEMATECH e-Handbook of Statistical Methods, Chapter 1: Exploratory Data Analysis, National Institute of Standards and Technology
- H. Wickham, M. Çetinkaya-Rundel and G. Grolemund, R for Data Science, 2nd ed., O'Reilly, 2023
- W. McKinney, Python for Data Analysis, 3rd ed., O'Reilly, 2022
- F. J. Anscombe, Graphs in Statistical Analysis, The American Statistician, 27(1), 17 to 21, 1973
Get one engineering email a week
New articles, worked examples and study notes every week. Free, no spam, unsubscribe any time.