Chrysolites Open Courses

AI Engineering and Data Analysis · Course book

Chapter 3: The Data Analysis Workflow

Pairs with Lesson 3: The Data Analyst's Workflow with Spreadsheets, SQL and Python

Organisations collect more data than ever, from sales systems, websites, sensors, surveys and spreadsheets, but data on its own answers nothing. A data analyst turns it into findings that help people decide: which products to stock, where customers drop out of a sign-up process, whether a new policy is working. This chapter follows the analyst's workflow from start to finish. It describes the modern data ecosystem and the analyst's place in it, then works through gathering, cleaning, analysing and communicating data, using the three main tools of the trade: spreadsheets, SQL and Python. It ends with a simple predictive model, worked out by hand, to show what model evaluation numbers actually mean.

The data ecosystem and the analyst's role

Data comes in three broad forms. Structured data fits neatly into rows and columns, like a table of orders. Semi-structured data has some organisation but not a fixed table shape, like JSON from a web service or an email with headers. Unstructured data, such as text, images and audio, has no predefined structure at all. It is stored in different kinds of repositories: relational databases for structured transactional data, data warehouses that combine cleaned data from many systems for analysis, data lakes that hold large amounts of raw data in any format, and big data platforms that spread processing across many machines when one is not enough.

Several roles share this ecosystem. Data engineers build the pipelines that move data from source systems into warehouses and lakes. Data analysts query and explore that data to answer business questions and report what they find. Data scientists build statistical and machine learning models to predict or explain outcomes. Business analysts connect findings to business processes and decisions. In smaller organisations, one person may do all four.

Analysis itself comes in four types of increasing ambition. Descriptive analysis asks what happened; diagnostic asks why; predictive asks what is likely to happen; and prescriptive asks what should be done about it.

StageWhat the analyst doesTypical tools
GatherIdentify sources and collect the data needed for the questionDatabase queries, exports, APIs, web scraping
WrangleClean, reshape, combine and check the dataSpreadsheets, SQL, Python with pandas
AnalyseSummarise, compare, look for patterns and test ideasPivot tables, SQL aggregates, statistics, models
CommunicateExplain findings clearly to the people who will act on themCharts, dashboards, short written reports, presentations

Gathering and wrangling data

Good analysis starts with a clear question, because the question decides which data is worth collecting. Data may come from internal databases, files exported from business systems, public datasets, APIs that return data on request over the web, or web scraping, which extracts information from web pages and must respect each site's terms of use.

Raw data is almost never ready to analyse, and analysts commonly spend much of their time on wrangling: making it accurate, consistent and usable. Typical problems include duplicate rows, missing values, inconsistent spellings ("NY", "New York", "new york"), numbers stored as text, dates in mixed formats and impossible values such as negative ages. Each needs a deliberate decision. Missing values may be removed, filled with a sensible value such as the median, or flagged; outliers must be checked to see whether they are errors or genuine but unusual cases. Recording every cleaning step makes the work repeatable and lets others check it.

Data quality goes hand in hand with privacy. Personal information should be collected only when needed, stored securely, and removed or anonymised where the analysis does not require it, in line with data protection laws.

Spreadsheets and SQL

Spreadsheets remain the most widely used analysis tool. Sorting and filtering find specific records quickly, formulas calculate new columns, and conditional formatting highlights values that need attention. The most powerful feature is the pivot table, which summarises thousands of rows in seconds, for example total sales by region and month, simply by dragging fields into rows, columns and values. Charts and simple dashboards can be built on top, and business intelligence tools such as IBM Cognos Analytics extend the same ideas to larger datasets and interactive dashboards.

A handful of functions do most of the work in spreadsheet analysis. SUMIFS, COUNTIFS and AVERAGEIFS total, count or average only the rows that meet conditions, such as sales in the North region in March. IF creates categories from values, for example labelling orders above $500 as large. Lookup functions such as XLOOKUP, or the older VLOOKUP, pull matching information from another table, such as a product's category from a product list. Text functions such as TRIM, PROPER and TEXTSPLIT tidy messy entries during cleaning. Keeping raw data on one sheet and calculations on another makes mistakes easier to find.

When data lives in a database, analysts use SQL, the standard language for querying relational databases. A small set of clauses covers most needs: SELECT chooses columns, FROM names the table, WHERE filters rows, GROUP BY groups rows for totals and averages, ORDER BY sorts, and JOIN combines related tables, such as orders with customers, using a shared key.

SELECT region, COUNT(*) AS orders, SUM(amount) AS revenue
FROM sales
WHERE order_date >= '2026-01-01'
GROUP BY region
ORDER BY revenue DESC;

This query counts orders and adds up revenue per region for the current year, then lists the regions from highest to lowest revenue. Python can send the same query to a database and receive the results as a table for further work, combining the strengths of both tools.

Python, exploration and a first model

Python's data libraries handle tasks too large or repetitive for a spreadsheet. pandas provides the DataFrame, a table that can be filtered, grouped, merged and summarised with short commands, and NumPy provides fast numerical arrays. Exploratory data analysis uses these to understand a dataset before drawing conclusions: summary statistics, the distribution of each variable, and correlations between variables. Visualisation libraries such as Matplotlib and Seaborn draw the histograms, box plots and scatter plots that reveal patterns, and tools such as Plotly and Dash turn them into interactive dashboards.

Exploration often leads to a predictive model. The simplest is linear regression, which fits a straight line y = a + bx through the data. Its slope b is the sum of (x − x̄)(y − ȳ) divided by the sum of (x − x̄)², where x̄ and ȳ are the means, and its intercept is a = ȳ − b x̄. Models are judged with error measures such as the mean squared error (MSE), the average squared gap between predictions and actual values, and R², the share of the variation in y that the model explains.

Worked example. A shop records weekly advertising spend x (in hundreds of dollars) and sales y (in thousands): (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). The means are x̄ = 15 ÷ 5 = 3 and ȳ = 20 ÷ 5 = 4. The deviations of x are −2, −1, 0, 1, 2 and of y are −2, 0, 1, 0, 1. The sum of products is 4 + 0 + 0 + 0 + 2 = 6 and the sum of squared x deviations is 4 + 1 + 0 + 1 + 4 = 10, so b = 6 ÷ 10 = 0.6 and a = 4 − 0.6 × 3 = 2.2. The predictions are 2.8, 3.4, 4.0, 4.6 and 5.2, giving errors of −0.8, 0.6, 1.0, −0.6 and −0.2. Their squares sum to 0.64 + 0.36 + 1.00 + 0.36 + 0.04 = 2.40, so MSE = 2.40 ÷ 5 = 0.48. The total variation in y is 4 + 0 + 1 + 0 + 1 = 6, so R² = 1 − 2.40 ÷ 6 = 0.60: advertising explains 60% of the variation in sales in this small sample.
y = 2.2 + 0.6x 0246 0123456 advertising spend ($100s)sales ($1,000s)
Figure 3.1 — The fitted line from the worked example. The dashed lines are the errors whose squares make up the MSE.

A result like this needs careful communication. It shows an association in five weeks of data, not proof that advertising causes sales, and five points are far too few for confident conclusions. Good analysts state such limits plainly, then present the finding with one clear chart and a short recommendation, such as testing a higher advertising budget for a month and measuring the result.

Choosing the right chart is part of communicating well. A line chart shows change over time; a bar chart compares categories; a scatter plot shows the relationship between two numeric variables, as in Figure 3.1; a histogram shows how one variable is distributed. Pie charts work only for a few parts of one whole and are often better replaced by bars. Every chart needs a title that states the finding, such as "North region sales rose 12% after the price change", labelled axes with units, and no decoration that distracts from the data. A dashboard should answer the few questions its audience asks most, not display every available number.

Check your understanding

  1. Classify each as structured, semi-structured or unstructured: a customer table, a folder of product photos, a JSON response from a weather API.
  2. Name the four types of analysis and give a business question for each.
  3. List four common data quality problems and how you would handle each.
  4. Write a SQL query that returns the average order amount per product category, highest first.
  5. Using the worked example's line, predict sales for an advertising spend of $600. Why should this prediction be treated with caution?
  6. Explain the difference between MSE and R² in plain language.

Install Chrysolites Open Courses

Android / Chrome / Edge: open the browser menu and choose Install app or Add to Home screen.

iPhone / iPad (Safari): tap the Share button, then Add to Home Screen.