Public
Edited
Oct 14, 2024
Paused
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sda = import("https://esm.sh/jsr/@nshiab/simple-data-analysis@3.13.9/web")
Insert cell
Insert cell
sdb = new sda.SimpleWebDB().start()
Insert cell
Insert cell
tableTemperature = {
// We create a new table.
const tableTemperature = sdb.newTable("temperature");

// We fetch daily temperatures for three cities.
await tableTemperature.fetchData(
"https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/dailyTemperatures.csv"
);

// We compute the decade from each date
// and put the result in the decade column.
await tableTemperature.addColumn(
"decade",
"integer",
"FLOOR(YEAR(time)/10)*10" // This is SQL
);

// We summarize the data by computing
// the average temperature
// per decade and per city.
await tableTemperature.summarize({
values: "t",
categories: ["decade", "id"],
summaries: "mean"
});

// We run linear regressions
// to check for trends.
await tableTemperature.linearRegressions({
x: "decade",
y: "mean",
categories: "id",
decimals: 4
});

// We return the table.
return tableTemperature;
}
Insert cell
Insert cell
Inputs.table(await tableTemperature.getData())
Insert cell
Insert cell
tableWithNames = {
// We create a new table.
const tableCities = sdb.newTable("cities");

// We load another file with
// the cities ids and names.
await tableCities.fetchData(
"https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/cities.csv"
);

// We join the two tables based on the ids.
// By default, join will automatically look
// for a common column, do a left join, and
// put the result in the left table.
await tableCities.join(tableTemperature);

// We select the columns of interest.
await tableCities.selectColumns(["city", "slope", "yIntercept", "r2"]);

// We return the table with the joined and selected data.
return tableCities;
}
Insert cell
Insert cell
Inputs.table(await tableWithNames.getData())
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more