Skip to content

Instantly share code, notes, and snippets.

@pguso
Last active September 10, 2021 07:52
Show Gist options
  • Select an option

  • Save pguso/9a8935567023e547d47d683dfcbf9dea to your computer and use it in GitHub Desktop.

Select an option

Save pguso/9a8935567023e547d47d683dfcbf9dea to your computer and use it in GitHub Desktop.
Setup Data Analysis Environment with Typescript and Plotly

Setup Data Analysis Environment with Typescript

Similar to Pandas & Jupyter Notebook in Python

In this tutorial we will set up an environment to make data analysis with typescript and write our code in an experimental environment like Jupyter Notebook.

The following part is copied from https://github.com/yunabe/tslab.

Installing tslab

Prerequisites

To get Python and Jupyter installed on your machine, the easiest way is to download and install anaconda https://www.anaconda.com/products/individual-d.

Installing tslab

First, install tslab with npm.

npm install -g tslab

Please make sure tslab command is available in your terminal.

tslab install --version

Then, register tslab to your Jupyter environment.

tslab install --python=python3

Getting Started

Install dependencies

Switch into a folder where you want to run your Typescript Notebook

cd your-folder

Install two packages to use them in your tslab environment

npm init -y

npm i danfojs-node tslab-plotly

Run tslab Notebook

jupyter lab

Run Examples

tslab Launcher

Place this code into a cell to see if danfo.js is working

import * as dfd from "danfojs-node"

let data = { "Name": ["Apples", "Mango", "Banana", "Pear"] ,
            "Count": [21, 5, 30, 10] ,
           "Price": [200, 300, 40, 250] }

let df = new dfd.DataFrame(data, {index: ["a", "b", "c", "d"]})
df.print()

dataframe

Place this code to see if Plotly is working

import Plotly from "tslab-plotly";
import * as tslab from "tslab";

Plotly.newPlot(tslab, [
  {
    x: [1, 2, 3, 4, 5],
    y: [1, 2, 4, 8, 16],
  },
]);

plotly

Further reading

tslab

danfo.js

Plotly for tslab

@pguso
Copy link
Author

pguso commented Sep 10, 2021

dataframe

plotly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment