TapCub is live — analytics, insights and live chat, free on one platform
Analytics

Data transformation techniques: eight steps on one sample dataset

Data transformation reshapes correct data for analysis. Eight techniques, from type conversion to scaling, applied to ten sample sessions with before and after tables and totals you can recompute.

Xu An Published Nov 22, 2026 12 min read Analytics
Sample data: revenue $1,200.50 / $149.00 / $147.00 against spend $200 / $60 / $120. Without lower-casing the source first, google's spend would not have joined.Sample data

Data transformation techniques reshape correct data so it can be analysed: convert types, standardise values, derive fields, aggregate, join, scale and pivot. Clean first, transform second, and check that totals reconcile after every step. In the ten-row sample here, 10 sessions, 4 orders and $1,496.50 survive the grouping unchanged.

What you will learn

  • Order matters: convert types, standardise, derive, join, aggregate, then scale
  • Reconcile after every step: the sample keeps 10 sessions, 4 orders and $1,496.50 before and after grouping
  • Never average averages: the overall duration is 81.0 s, the mean of group averages 83.9 s

What is data transformation, and where does it sit?

Data transformation is changing the shape, format or scale of data that is already correct so that it can be analysed. Cleaning fixes what is wrong (duplicates, missing values, typos); transformation reshapes what is right. The two blur together in practice, but the order matters: clean first, transform second, because a transformation applied to dirty data multiplies the damage. The cleaning steps have their own article, data cleaning techniques. Where the transformation runs, before loading or after, is the ETL versus ELT question covered in ETL vs ELT.

This article takes eight techniques and applies them, one at a time, to the same ten rows of sample data, so you can see exactly what each one changes. Every number below can be recomputed from the table in the next section.

What does the raw data look like?

Sample data: ten website sessions exported as text, the way many tools hand them over.

#TimeLanding pageDurationOrder amount
103/02/2026 09:14/pricing?utm_source=Google&utm_medium=cpc1m 05s$0.00
203/02/2026 09:20/pricing?utm_source=google&utm_medium=cpc0m 48s$49.00
303/02/2026 11:02/blog/x?utm_source=Newsletter&utm_medium=email2m 30s$0.00
403/02/2026 14:40/pricing?utm_source=google&utm_medium=cpc0m 20s$0.00
503/03/2026 08:45/pricing?utm_source=google&utm_medium=cpc0m 22s$0.00
603/03/2026 13:31/blog/y?utm_source=newsletter&utm_medium=email3m 10s$1,200.50
703/03/2026 15:10/?utm_source=linkedin&utm_medium=social0m 15s$0.00
803/04/2026 10:00/pricing?utm_source=LinkedIn&utm_medium=social1m 40s$149.00
903/04/2026 16:20/pricing?utm_source=google&utm_medium=cpc2m 05s$98.00
1003/04/2026 17:05/blog/z?utm_source=newsletter&utm_medium=email1m 15s$0.00

You cannot sum "$1,200.50", you cannot subtract "1m 05s" from "2m 30s", and "Google" is not equal to "google". Everything in this article starts from those three facts.

How do you convert types?

Turn text into the type the question needs: durations into seconds, amounts into numbers, timestamps into dates. Type conversion is the first transformation because every later one needs the right type.

FieldBeforeAfterRule
Duration, row 1"1m 05s"65minutes × 60 + seconds
Duration, row 6"3m 10s"1903 × 60 + 10
Amount, row 6"$1,200.50"1200.50strip "$" and the thousands comma
Time, row 1"03/02/2026 09:14"2026-03-02read as month/day/year, keep the date

The date is the dangerous one. "03/02/2026" is 2 March in the US format and 3 February in most other countries. Decide the input format from the source system, not from the value. Then write dates out in the unambiguous year-month-day form, which is the format RFC 3339 defines for internet timestamps (2026-03-02T09:14:00Z).

How do you standardise values?

Make equal things identical: lower-case the text, trim spaces, use one spelling. Rows 1 and 2 are the same source, "Google" and "google", and a grouping query would count them as two. After lower-casing utm_source, the ten rows have three sources: google (rows 1, 2, 4, 5, 9), newsletter (3, 6, 10) and linkedin (7, 8).

Standardise to one time zone and one unit at the same time. If amounts arrive in two currencies, convert them to one with a stated rate and date before adding; never add dollars to euros and hope.

How do you derive new fields?

Create a column that answers a question the raw columns do not. Three derivations from the sample:

  1. Extract: the source from the URL, for example utm_source=Google becomes google.
  2. Flag: ordered = amount > 0, which makes row 2 (49.00), 6, 8 and 9 orders and the other six not.
  3. Bin: group the continuous duration into labels, here under 30 seconds, 30–119 seconds and 120 seconds or more.
BucketRowsCount
< 30 s4, 5, 73
30–119 s1, 2, 8, 104
≥ 120 s3, 6, 93

Binning loses detail on purpose. Keep the original seconds column too, so you can re-bin when the thresholds change.

How do you aggregate?

Group rows and summarise each group; this is the step that turns events into a report. The pandas documentation describes the pattern as split, apply, combine: split the data into groups, apply a function to each, and combine the results. Grouping the ten rows by source:

SourceSessionsOrdersConversion rateRevenueAverage duration
google5240.0%$147.0056.0 s
newsletter3133.3%$1,200.50138.3 s
linkedin2150.0%$149.0057.5 s
Total10440.0%$1,496.5081.0 s

Check the totals against the input: 5 + 3 + 2 = 10 sessions, 2 + 1 + 1 = 4 orders, and $147.00 + $1,200.50 + $149.00 = $1,496.50, the sum of the Amount column. If an aggregate does not reconcile with its input, a join or a filter dropped or doubled rows.

Note the trap in the average row: the overall average duration (810 ÷ 10 = 81.0 seconds) is not the average of the three group averages (83.9 seconds). Always aggregate from the base rows, never average averages.

How do you join in other data?

Add columns from a second table by a key, so that each row gains context. Here the second table is spend per source, an input from your own records (sample data: google $120, newsletter $200, linkedin $60). Joining on source and dividing revenue by spend:

SourceRevenueSpendRevenue ÷ spend
google$147.00$1201.23
newsletter$1,200.50$2006.00
linkedin$149.00$602.48

Two checks before trusting a join. Count the rows before and after (three sources, three rows, no loss); and make sure the key is unique on the lookup side, or one source row will become two and the revenue will double. Join keys also depend on step two: if Google had not been lower-cased, google's spend would not have matched.

app.tapcub.com

Revenue ÷ spend by source after the join

sample data
newsletter6.00
linkedin2.48
google1.23
Sample data
Sample data: revenue $1,200.50 / $149.00 / $147.00 against spend $200 / $60 / $120. Without lower-casing the source first, google's spend would not have joined.

When do you normalise or scale values?

Rescale when you must compare or combine columns measured in different units, for example when you feed them into a model or a score. The scikit-learn documentation describes two standard options. Min-max scaling maps the smallest value to 0 and the largest to 1 with (x − min) ÷ (max − min). Standardising subtracts the mean and divides by the standard deviation, giving a z-score. Applying both to the average durations of the three sources (56.0, 138.3, 57.5 seconds; mean 83.9, sample standard deviation 47.1):

SourceAverage durationMin-maxZ-score
google56.0 s0.000−0.59
newsletter138.3 s1.0001.15
linkedin57.5 s0.018−0.56

One outlier decides the whole picture: because newsletter is so far from the others, min-max pushes the other two to almost the same spot near zero. For a skewed column such as revenue ($147, $1,200.50, $149), a log transform compresses the range: log10(x + 1) gives 2.17, 3.08 and 2.18, so the large value no longer dominates.

Do not scale for a report people read in real units. Scale for models and scores, and keep the original column.

How do you encode categories and reshape a table?

Encode categories as numbers only when a tool needs numbers; reshape when the layout does not fit the question. Two quick examples:

  • One-hot encoding: one 0/1 column per category. Source becomes three columns, is_google, is_newsletter and is_linkedin, and each row has exactly one 1.
  • Pivot: turn rows into columns to compare days side by side. Sessions by day and source from the sample:
Daygooglenewsletterlinkedin
2026-03-02310
2026-03-03111
2026-03-04111

The pivot adds up to 10 as well (3 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 10). Wide layouts are easy to read; long layouts (one row per day and source) are easier to filter and chart, so keep the long table and pivot only for display.

In what order should you apply them?

Convert types, standardise, derive, join, aggregate, then scale, and reconcile counts after every step that can change the row count. Types come first because later steps need them. Standardising before joining prevents silent mismatches. Aggregating before scaling avoids scaling rows you are about to collapse. A reconciliation line after each step, such as "10 rows in, 10 rows out" or "sum of amounts $1,496.50 before and after", catches a broken join the moment it happens.

TechniqueWhat it changesSample result
Convert typesText into numbers and dates"1m 05s" becomes 65 seconds
StandardiseCase, spelling, units"Google" and "google" become one source
Derive and binAdds columnsDuration split into 3 buckets (3 / 4 / 3 sessions)
AggregateRows into group totals3 sources from 10 sessions
JoinAdds columns from another tableRevenue ÷ spend 1.23 / 6.00 / 2.48
ScaleCommon range or z-scoreMin-max 0 to 1; z-scores −0.59 to 1.15
Encode and pivotLayout and numeric labels3 one-hot columns; days by source grid

Sample data: ten sessions; all values can be recomputed from the table in the article.

What mistakes break a transformation?

Five mistakes cause most wrong numbers after a transformation.

  1. Transforming before cleaning. One duplicated order row doubles a revenue sum, and no later step will notice.
  2. Overwriting the raw column. Keep "1m 05s" next to 65, so you can redo a step when the rule changes.
  3. Joining at the wrong grain. Joining a spend-per-day table to session rows repeats each day's spend on every session of that day, and the total spend multiplies.
  4. Binning without writing down the thresholds. "Under 30 seconds" and "30 seconds or less" put different rows in different buckets.
  5. Leaving the time zone unstated. A session at 23:50 in one time zone is on the next day in another, which moves it between days in a pivot.

How to do these transformations in TapCub

Take the sample above: sessions with a source, a duration and an order amount, and spend you hold separately. TapCub does the conversion and standardisation at collection, and gives you two places to do the rest.

  1. Sessions and sources arrive already typed: the script records time, duration and UTM parameters as fields, so you do not parse text like "1m 05s". Check the sources in Web analytics › Sources, where channel rules can be configured to merge variants.
  2. For derived fields and ratios, open All-platform analytics › Behavior › Metrics & SQL and define a metric with a formula, or an event plus an aggregation such as distinct users or per-person average; SQL is available in the same place for custom group-bys.
  3. For the join with spend, import cost by day, channel, source and campaign in All-platform analytics › Business › Channel ROI, by CSV or entry by entry. The page then gives cost per click (spend ÷ sessions), cost per acquisition (spend ÷ purchases in orders) and return on ad spend, grouped by channel, source or campaign.
  4. To bring in an external table of events or user attributes, use All-platform analytics › Data › Data import (CSV files of up to 100,000 lines each).

TapCub does not load data into your warehouse or run transformation jobs there; for that, export raw detail from All-platform analytics › Data › Data export and transform it in your own pipeline.

FAQ

What are the main data transformation techniques?

The common ones are type conversion, standardising values, deriving new fields, binning, aggregating, joining, normalising or scaling, encoding categories and reshaping (pivoting). Most analysis uses the first six; scaling and encoding matter mainly when the data feeds a model.

What is the difference between data cleaning and data transformation?

Cleaning corrects errors: duplicates, missing values and typos. Transformation changes correct data into a more useful shape, format or scale: seconds instead of "1m 05s", totals by source instead of raw sessions. Clean first, because transforming dirty data hides the errors inside the result.

What is the difference between normalisation and standardisation?

Normalisation (min-max) rescales values to a fixed range, usually 0 to 1, with (x − min) ÷ (max − min). Standardisation subtracts the mean and divides by the standard deviation, so values describe how many standard deviations from average they are. Min-max is sensitive to outliers; standardising is less so.

When should you aggregate before or after joining?

Aggregate first when the lookup table is at a coarser level than your rows, for instance spend per source, and join after. Join first when you need row-level context. In both cases reconcile totals before and after, because a duplicate key on the lookup side silently doubles values.

Do you need to transform data before analysing it?

Yes, almost always, but only as much as the question needs. Convert types and standardise values every time. Scale and encode only when the data goes into a model or score. Keep the original columns so you can redo a step when a rule changes.

Sources

Filed underAnalytics

Was this article helpful?

We use your answers to fix and expand this page.

Xu An

Customer Experience Consultant

Writes about live chat, visitor conversations, and self-service, sharing practical ways to make customer communication clearer and more effective.

Do the transformations where the data already lives

Custom metrics, SQL, spend import and raw export in one project, so the rows you transform are the rows you collected.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics