-
Notifications
You must be signed in to change notification settings - Fork 2
Updating sda page #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nshiab
wants to merge
3
commits into
Fil:main
Choose a base branch
from
nshiab:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,76 +4,78 @@ index: true | |
|
|
||
| # Simple data analysis | ||
|
|
||
| [Simple data analysis](https://nshiab.github.io/simple-data-analysis/), a library maintained by computational journalist Nael Shiab, purports to be “a high-performance and convenient solution in JavaScript for data analysis. It's based on DuckDB and inspired by Pandas (Python) and the Tidyverse (R).” | ||
| [Simple data analysis](https://github.com/nshiab/simple-data-analysis), a library maintained by computational journalist Nael Shiab, purports to be “a high-performance and convenient solution in JavaScript for data analysis. It’s based on DuckDB and inspired by Pandas (Python) and the Tidyverse (R).” | ||
|
|
||
| ```js echo | ||
| import {SimpleDB} from "npm:simple-data-analysis@2"; | ||
| import { SimpleWebDB } from "https://esm.sh/jsr/@nshiab/simple-data-analysis@3.15.3/web"; | ||
| ``` | ||
|
|
||
| _Note: the API of this library has changed in version 3. This page would need a refresher._ | ||
|
|
||
| ```js echo | ||
| // We start a new instance of SimpleDB | ||
| const sdb = new SimpleDB(); | ||
|
|
||
| // We load daily temperatures for three cities. | ||
| // We put the data in the table dailyTemperatures. | ||
| await sdb.loadData( | ||
| "dailyTemperatures", | ||
| "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/dailyTemperatures.csv" | ||
| // We start a new instance of SimpleWebDB | ||
| const sdb = new SimpleWebDB(); | ||
|
|
||
| // 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", | ||
| ); | ||
|
Comment on lines
+21
to
23
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: host this file in /data/ |
||
|
|
||
| // We compute the decade from each date | ||
| // and put the result in the decade column. | ||
| await sdb.addColumn( | ||
| "dailyTemperatures", | ||
| await tableTemperature.addColumn( | ||
| "decade", | ||
| "integer", | ||
| "FLOOR(YEAR(time)/10)*10" // This is SQL | ||
| "FLOOR(YEAR(time)/10)*10", // This is SQL | ||
| ); | ||
|
|
||
| // We summarize the data by computing | ||
| // the average dailyTemperature | ||
| // the average temperature | ||
| // per decade and per city. | ||
| await sdb.summarize("dailyTemperatures", { | ||
| await tableTemperature.summarize({ | ||
| values: "t", | ||
| categories: ["decade", "id"], | ||
| summaries: "mean" | ||
| summaries: "mean", | ||
| }); | ||
|
|
||
| // We run linear regressions | ||
| // to check for trends. | ||
| await sdb.linearRegressions("dailyTemperatures", { | ||
| await tableTemperature.linearRegressions({ | ||
| x: "decade", | ||
| y: "mean", | ||
| categories: "id", | ||
| decimals: 4 | ||
| decimals: 4, | ||
| }); | ||
|
|
||
| // The dailyTemperature table does not have | ||
| // The tableTemperature does not have | ||
| // the name of the cities, just the ids. | ||
| // We load another file with the names | ||
| // in the table cities. | ||
| await sdb.loadData( | ||
| "cities", | ||
| "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/cities.csv" | ||
| // in a new table. | ||
|
|
||
| // 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. By default, | ||
| // join searches for a common column | ||
| // and does a left join. The result is stored in | ||
| // the left table (dailyTemperatures here). | ||
| await sdb.join("dailyTemperatures", "cities"); | ||
| // 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 | ||
| // after the join operation. | ||
| await sdb.selectColumns("dailyTemperatures", ["city", "slope", "yIntercept", "r2"]); | ||
| // We select the columns of interest. | ||
| await tableCities.selectColumns(["city", "slope", "yIntercept", "r2"]); | ||
|
|
||
| // We log the results table. | ||
| await sdb.logTable("dailyTemperatures"); | ||
| await tableCities.logTable(); | ||
|
|
||
| // We store the data in a variable. | ||
| const results = await sdb.getData("dailyTemperatures"); | ||
| const results = await tableCities.getData(); | ||
|
|
||
| display(Inputs.table(results)); | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd want this to work:
unfortunately it fails with
Missing "./web" specifier in "@jsr/nshiab__simple-data-analysis" package, which may be an issue with the package or with framework (?). I'm not sure how to fix it yet.Note that ideally, I'd want this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also want to use a self-hosted version of DuckDB, instead of loading it from jsdeliver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I see in the console when I switch to
import { SimpleWebDB } from "jsr:@nshiab/simple-data-analysis@3.15.3/web";, it's a problem with the library. I'll investigate and come back to you!