Home Data Building Data-Driven Applications with Danfo.js

Building Data-Driven Applications with Danfo.js

By Rising Odegua , Stephen Oni
books-svg-icon Book
Subscription FREE
eBook + Subscription $15.99
eBook $39.99
Print + eBook $48.99
READ FOR FREE Free Trial for 7 days. $15.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
READ FOR FREE Free Trial for 7 days. $15.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
Subscription FREE
eBook + Subscription $15.99
eBook $39.99
Print + eBook $48.99
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
  1. Free Chapter
    Chapter 1: An Overview of Modern JavaScript
About this book
Most data analysts use Python and pandas for data processing for the convenience and performance these libraries provide. However, JavaScript developers have always wanted to use machine learning in the browser as well. This book focuses on how Danfo.js brings data processing, analysis, and ML tools to JavaScript developers and how to make the most of this library to build data-driven applications. Starting with an overview of modern JavaScript, you’ll cover data analysis and transformation with Danfo.js and Dnotebook. The book then shows you how to load different datasets, combine and analyze them by performing operations such as handling missing values and string manipulations. You’ll also get to grips with data plotting, visualization, aggregation, and group operations by combining Danfo.js with Plotly. As you advance, you’ll create a no-code data analysis and handling system and create-react-app, react-table, react-chart, Draggable.js, and tailwindcss, and understand how to use TensorFlow.js and Danfo.js to build a recommendation system. Finally, you’ll build a Twitter analytics dashboard powered by Danfo.js, Next.js, node-nlp, and Twit.js. By the end of this app development book, you’ll be able to build and embed data analytics, visualization, and ML capabilities into any JavaScript app in server-side Node.js or the browser.
Publication date:
September 2021
Publisher
Packt
Pages
476
ISBN
9781801070850

 

Chapter 1: An Overview of Modern JavaScript

In this chapter, we will talk about some core JavaScript concepts. If you are new to JavaScript and need an introduction, check out Chapter 13, Appendix: Essential JavaScript Concepts.

Understanding some of the modern concepts of JavaScript is not a prerequisite to using Danfo.js, but we recommend going through this chapter if you're new to JavaScript or coming from a Python background, the reason being that we'll be using most of the concepts introduced here when building applications with Danfo.js. Also, it is worth mentioning that many of the concepts introduced here will, in general, help you to write better JavaScript.

This chapter introduces you to some modern JavaScript concepts, and by the end, you will have learned and understand the following concepts:

  • Understanding the difference between let and var
  • Destructuring
  • Spread syntax
  • Overview of scopes and closures
  • Understanding Array and Object methods
  • Understanding the this property
  • Arrow functions
  • Promises and async/await
  • Object-oriented programming and JavaScript classes
  • Setting up a modern JavaScript environment with transpilers
  • Unit testing with Mocha and Chai
 

Technical requirements

The major requirement is to have Node.js and NPM installed. You can follow the official installation guide available at https://nodejs.org/en/download/ to install Node for your operating system. The code for this chapter can be found in the GitHub repo here: https://github.com/PacktPublishing/Building-Data-Driven-Applications-with-Danfo.js/tree/main/Chapter01.

We will start this section by understanding the difference between let and var, and why you should use let more often.

 

Understanding the difference between let and var

Before ECMA 6, the common way of creating a variable was with the use of var. However, using var sometimes introduces bugs that mostly show up at runtime and others that are not revealed at runtime but may affect the way your code works.

Some of the properties of var that introduce bugs as mentioned in the previous paragraph are as follows:

  • var allows the redeclaration of variables.
  • var is not blocked scope; hence, it is either attached to the global scope or to a function scope.

Let's discuss the two properties listed above in detail.

var allows the redeclaration of variables

var gives users access to redeclare variables along the line, hence overriding the previous variable of the same name. This feature might not show an error if not caught, but will certainly affect the behavior of the code:

var population_count = 490; 
var new_count = 10; 
 
//along the line; you mistakenly re-declare the variable 
var population_count = "490"
 
//do some arithmetic operation with the variable 
var total_count = population_count + new_count 
 
//output: "49010" 

In the preceding code snippet, there won't be any error, but the main objective of the code is altered just because var did not alert us that such a variable has been declared already.

Let's say we replace var with let, as shown in the following code:

let population_count = 490;
// ...some other code goes here 
let population_count = "490"
 
//output: Error: Identifier population count as already being declared 

You can see from the preceding error output that let, unlike var, will not allow you to declare a variable in the same namespace twice.

Next, let's look at the scope property of variables declared with var.

var is not a blocked scope

Variables declared with var have the following properties:

  • They are readily available in the scope to which they are defined.
  • They are available to scope within the range they are being declared.

In the following code, we will check how the estimate variable declared with var is accessible across all the scope within the variable declaration scope:

var estimate = 6000;
function calculate_estimate() {
  console.log(estimate);
}
calculate_estimate() // output 6000
 
if(true){
 console.log(estimate);
}

Now, for a blocked scope such as if, while loop, and for loop, the code within the blocked scope is meant to be run when the scope is available. Likewise, the variable is meant to exist only when the scope is available, and once the scope is not available again, the variable should not be accessible.

Declaring variables with var makes the preceding statement not possible. In the following code, we declare a variable using var and investigate its availability across all possible scopes:

if(true){
 var estimate = 6000;
}
console.log(estimate)

This will output the estimate as 6000. The variable is not meant to exist outside the if block. Using let helps to solve this:

if(true){
 let estimate = 6000;
}
console.log(estimate)
//output: ReferenceError: estimate is not defined

This shows that using let to declare variables helps reduce unprecedented bugs in your code. In the next section, we'll discuss another important concept called destructuring.

                     
About the Authors
  • Rising Odegua

    Rising Odegua is the co-creator of Danfo.js and Dnotebook. He is a software and machine learning engineer with experience building data-driven applications in languages such as Python and JavaScript. Rising is actively engaged in building the developer ecosystem by giving talks, providing direct/indirect mentorship, working on open source projects, hosting meetups, and writing tutorials.

    Browse publications by this author
  • Stephen Oni

    Stephen Oni is the co-creator of Danfo.js and Dnotebook. He is a software developer at Datopian, building data-driven platforms and tools. He is also an open source developer building tools that intersect the web and machine learning.

    Browse publications by this author
Building Data-Driven Applications with Danfo.js
Unlock this book and the full library FREE for 7 days
Start now