liveBook · Manning

Data wrangling

As explained in D3.js in Action, Third Edition

Data wrangling is the process of transforming, cleaning, and reshaping data for subsequent use or analysis.

Data wrangling transforms, cleans, and reshapes data so it can support analysis and visualization. In JavaScript, it commonly starts with arrays of objects loaded from datasets such as CSV files. section 1.2.5

A practical JavaScript workflow includes:

  • Iterate through each datum with forEach and convert values such as string-formatted IDs into numbers. section 1.2.5
  • Use map to reshape a dataset into a simpler array, such as a list of employee names. section 1.2.5
  • Use filter to isolate every datum matching a condition, or find to retrieve one unique matching datum. section 1.2.5
  • Clean, format, and prepare data before analysis, then prototype visualizations before committing to a refined D3 implementation. section 1.1.2

Preparing employee data

Given an array of employee objects, `data.forEach(d => { d.id = +d.id; });` converts each ID from a string to a number. `data.map(d => d.name)` produces names for labeling a visualization, while `data.filter(d => d.works_with_d3)` selects matching employees and `data.find(d => d.id === 3)` locates one employee. section 1.2.5

const data = [
 {id:"1", name:"Zoe", position:"Data analyst", works_with_d3:false},
 {id:"2", name:"James", position:"Frontend developer", works_with_d3:true},
 {id:"3", name:"Alice", position:"Fullstack developer",works_with_d3:true},
 {id:"4", name:"Hubert", position:"Designer", works_with_d3:false}
];

Inspect the compact employee dataset used for the wrangling operations. section 1.2.5

How D3.js in Action, Third Edition covers it

How deep it goes
Explains property access, type conversion, iteration, mapping, filtering, and finding, but does not cover all manipulation techniques.
Examples
Demonstrates employee records, numeric ID conversion, name extraction, conditional filtering, and unique-record lookup.
What it assumes
Assumes basic JavaScript arrays, objects, property access, and loops while introducing dataset-oriented manipulation.
What you can do after
Apply it via JavaScript array methods to clean, reshape, and select records for visualization.
How it connects
Connects data wrangling with JavaScript, CSV, data analysis, data visualization, and D3.js.

Also explained in

Compare how 5 books explain data wrangling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.