Public
Edited
Oct 14
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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more