Divide Large Data Set into Smaller Data Sets

Craig Oda
CodeCakes
Published in
2 min readOct 28, 2018

US Rainfall by State part 2 — divide large data set into 5 separate data sets

The Code Cakes Project

Previous Lesson

Remove Characters from Beginning of JavaScript String

Overview

There are 50 states in the data. Graphing the 50 states on a single graph will make the graph difficult to read. We will divide the one large data set you built in the previous lesson into 5 separate data sets.

In a future lesson, we will create clickable buttons to change between the data sets.

Demo of Completed Project

https://codetricity.github.io/codecakes-rainfall/index.html

Code for This Lesson

https://github.com/codetricity/codecakes-rainfall/blob/master/lessons/02/js/main.js

Steps

Create new code in the d3.csv promise. Put it after the code you built in the previous lesson to clean the data.

Create 5 empty arrays.

Loop through data array and populate each array with rainfall data from 10 states.

Bundle arrays into into one larger array called, datasets.

Use console.log to print out datasets.

console.log(datasets);

Syntax Review

Next Lesson

Code Cakes Project Information

--

--

Craig Oda
CodeCakes

open source advocate, writer, Flutter developer, father, husband, fly fisherman, surfer