Data transformation

On this page 7

Data transformation is the process of converting data from its source structure, format or values into the form that a target system, model or analysis requires. In data processing it is the step between extraction and use: raw records are cleaned, typed, joined, reshaped, aggregated and enriched so that downstream consumers receive consistent, reliable and fit-for-purpose data.

Transformation appears in nearly every data workflow, from a spreadsheet formula to a pipeline processing billions of rows in Apache Spark. It is the T in ETL and ELT, and the quality of its logic largely determines whether reports, dashboards and machine learning features can be trusted.

How data transformation works

A transformation takes one or more input datasets, applies a sequence of operations defined in code or configuration, and writes one or more output datasets. The operations are usually expressed in SQL, in dataframe libraries such as pandas or Spark, or in visual tools that generate equivalent code.

Well-designed transformations are deterministic and idempotent: running the same logic on the same inputs always produces the same outputs, and rerunning a job does not duplicate data. These properties make pipelines testable and allow safe reprocessing after a failure or a logic change.

The main families of operations are summarized below.

CategoryWhat it doesExample
StructuralChanges the shape of dataPivoting, unpivoting, flattening nested JSON
Type and formatConverts types and representationsText to date, local time to UTC
CleaningFixes or removes invalid valuesTrimming spaces, standardizing codes
IntegrationCombines several sourcesJoins, unions, record linkage
AggregationSummarizes rows into groupsDaily revenue per store
DerivationCreates new fieldsCustomer age, order margin
FilteringSelects relevant rows or columnsRemoving test accounts
Main categories of transformation operations

Where transformation happens in a pipeline

The position of transformation in the pipeline defines the two dominant architectures. In ETL, data is transformed before it is loaded into the target. In ELT, raw data is loaded first and transformed inside a scalable warehouse or lakehouse.

AspectETLELT
Transformation locationSeparate processing engineInside the warehouse or lakehouse
Raw data retainedOften not in the targetYes, enabling reprocessing
Typical toolsIntegration platforms, Spark jobsSQL models in the warehouse
StrengthSensitive data filtered before loadingFlexibility and fast iteration
WeaknessRework needs a new extractionRaw storage cost and governance load
ETL compared with ELT

Many organizations organize ELT outputs into layered zones, often called raw, cleaned and curated, or bronze, silver and gold. Each layer applies a defined class of transformation, which keeps logic modular and makes lineage easier to trace.

Data transformation is a broad umbrella, and several neighboring terms describe parts of it with a narrower focus. Distinguishing them clarifies who does the work and for what purpose.

TermFocusRelation to transformation
Data cleaningCorrecting errors and inconsistenciesA subset of transformation
Data wranglingInteractive, exploratory reshapingAd hoc transformation by analysts
Data aggregationSummarizing detailed recordsOne type of transformation
Data enrichmentAdding attributes from other sourcesIntegration-focused transformation
Feature engineeringCreating model input variablesTransformation aimed at machine learning
Data validationChecking rules and expectationsA control around transformation
Data transformation and neighboring terms

In short, cleaning, aggregation and enrichment are kinds of transformation, wrangling is a working style, and validation is the safeguard that confirms each transformation produced what it should.

Batch and streaming transformation

Transformations run either on bounded datasets in batch processing or on unbounded event streams. Batch jobs process a complete partition, such as one day of orders, and are simpler to reason about and reprocess. Streaming transformations process records continuously with latency from milliseconds to seconds.

Streaming adds difficulties that batch processing avoids: late-arriving events, stateful operations such as windowed aggregation and joins across streams, and the need for exactly-once guarantees. Many teams therefore keep heavy historical transformation in batch and apply only lightweight, time-critical logic in streams.

The choice between the two modes should follow the freshness the consumer actually needs. A finance report reconciled once a day gains nothing from second-level latency, while fraud scoring or inventory alerts lose value within minutes. A hybrid design, sometimes called a lambda or kappa architecture, combines a streaming path for recent data with batch recomputation that corrects it later.

Pitfalls and good practice

Most transformation failures are silent: the job succeeds, but the output is wrong. Typical causes are joins that multiply rows, changes in source schemas and hidden assumptions about time zones or units.

ProblemSymptomPrevention
Join fan-outTotals inflated after a joinCheck key uniqueness, compare row counts
Schema driftNulls or failures after source changeSchema contracts, automated alerts
Time zone mismatchDaily totals shifted by hoursStore UTC, convert only for display
Lossy type castingTruncated decimals or identifiersExplicit types, precision tests
Undocumented business logicConflicting metric definitionsVersion-controlled, reviewed models
Frequent transformation errors
  • Keep transformation logic in version control and review it like application code.
  • Test outputs automatically for uniqueness, non-null keys, accepted values and row counts.
  • Record lineage so every output column can be traced to its sources.
  • Process incrementally where volumes are large, while keeping a full rebuild possible.

In everyday language

Data transformation is like preparing ingredients before cooking. Vegetables arrive from different farms, some dirty, some whole, some in odd sizes. Before they go into the pot, someone washes, peels, chops and measures them so the recipe works.

Data arrives the same way, from many systems in many formats. Transformation cleans it, puts it into the same shape and combines it so that a report or an application can use it. The main point is that good results depend on careful preparation, because a mistake in this step quietly spoils everything that follows.

Seen in the real world

A regional retail chain with 140 stores wants one daily sales dashboard. Point-of-sale systems export transactions in two different formats, the online shop stores orders as nested JSON, and returns live in a separate system. Each night, raw files are loaded into a cloud warehouse, where a series of SQL models standardizes timestamps to UTC, maps product codes to one catalog, flattens the online orders and subtracts returns.

A final model aggregates net sales per store, day and category. Automated tests check that every transaction has a store identifier and that totals match the source systems within a small tolerance. When one store’s system update began sending prices in cents, the row-level test caught the hundredfold jump before the dashboard refreshed, and the team corrected the mapping the same morning, so managers never saw the wrong figures.