Platform
Resources
Pricing
Sign in
Get started
56fc95d9361213d8
Workspace
Fork
Public
By
56fc95d9361213d8
Edited
Jun 7, 2023
Fork of
Introduction to data wrangling and analysis in JavaScript — Session 1 Follow-along version
1
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
burrito
=
[
"chicken"
,
4.2
,
false
,
"avocado"
,
11.99
,
"beans"
]
Insert cell
Insert cell
// Access the fourth element in burrito:
burrito
[
3
]
Insert cell
Insert cell
// Find the length of the burrito array:
burrito
.
length
Insert cell
Insert cell
// Find the index (position) of the value 4.2 in burrito:
burrito
.
indexOf
(
4.2
)
Insert cell
Insert cell
Insert cell
Insert cell
droids
=
[
{
name
:
"C-3PO"
,
color
:
"gold"
,
height
:
167
}
,
{
name
:
"R2D2"
,
color
:
"white/blue"
,
height
:
96
}
,
{
name
:
"BB-8"
,
color
:
"white/orange"
,
height
:
26.4
}
]
Insert cell
Insert cell
// Find the length of the droids array:
droids
.
length
Insert cell
Insert cell
// Find the value of "height" for the third element in droids (BB-8's height):
droids
[
2
]
[
"height"
]
// alternately
droids
[
2
]
.
height
Insert cell
Insert cell
// Find the keys of the first element in the droids array:
Object
.
keys
(
droids
[
0
]
)
Insert cell
Insert cell
Insert cell
Insert cell
restaurantBills
=
[
{
bill
:
49.51
,
tipPercent
:
0.15
}
,
{
bill
:
112.40
,
tipPercent
:
0.22
}
,
{
bill
:
68.25
,
tipPercent
:
0.18
}
,
{
bill
:
27.37
,
tipPercent
:
0.12
}
,
{
bill
:
50.18
,
tipPercent
:
0.17
}
]
Insert cell
Insert cell
// Calculate tips for each bill here:
restaurantBills
.
map
(
d
=>
d
.
bill
*
d
.
tipPercent
)
Insert cell
// returns same result by putting d within ()
restaurantBills
.
map
(
(
d
)
=>
d
.
bill
*
d
.
tipPercent
)
Insert cell
Insert cell
Insert cell
Insert cell
nyc_water
=
FileAttachment
(
"nyc_water.csv"
)
.
csv
(
{
typed
:
true
}
)
Insert cell
nyc_water
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Insert cell
// Access the third element in the array:
nyc_water
[
2
]
Insert cell
Insert cell
// Access Consumption (HCF) from the ninth element in the array:
nyc_water
[
8
]
[
'Consumption (HCF)'
]
Insert cell
Insert cell
// Access Location from the 100th element in the array:
nyc_water
[
99
]
.
Location
Insert cell
Insert cell
// Use Array.map and an arrow array to return and array with the ratio of Current Charges to Consumption (HCF):
nyc_water
.
map
(
d
=>
d
[
'Current Charges'
]
/
d
[
'Consumption (HCF)'
]
)
Insert cell
Insert cell
Insert cell
Insert cell
nyc_water
Clear All
Swap X/Y
Customize
X
Consumption (HCF)
Y
—
Current Charges
Color
Consumption (HCF)
Size
—
Facet X
—
Facet Y
—
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.
Insert cell
// Create and customize a scatterplot of Consumption (HCF) and Current Charges from the nyc_water data:
Plot
.
plot
(
{
x
:
{
type
:
"log"
}
,
y
:
{
type
:
"log"
}
,
marks
:
[
Plot
.
dot
(
nyc_water
,
{
x
:
'Consumption (HCF)'
,
y
:
"Current Charges"
}
)
]
}
)
Insert cell
Insert cell
import
{
showMe
}
from
"@observablehq/show-me"
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.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
burrito
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
droids
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
restaurantBills
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
nyc_water
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
nyc_water
File attachments
nyc_water.csv
CSV
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
nyc_water
File attachments
nyc_water.csv
CSV
Customize
Clear
Title
Subtitle
Caption
Height
Width
Auto
Full
Margin
Top
Right
Bottom
Left
Inset
Legend
Auto
None
X label
X scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
X options
Grid
Reverse
Y label
Y scale
Auto
Scale
Auto
linear
log
sqrt
symlog
point
band
Y options
Grid
Reverse
Color scheme
Auto
Color scheme
Auto
Default color schemes
Sequential
Diverging
Cyclical
Categorical
Sequential color schemes
Blues
Greens
Greys
Oranges
Purples
Reds
Turbo
Viridis
Inferno
Magma
Plasma
Cividis
Warm
Cool
BuGn
BuPu
GnBu
OrRd
PuBuGn
PuBu
PuRd
RdPu
YlGnBu
YlGn
YlOrBr
YlOrRd
Diverging color schemes
BrBG
PRGn
PiYG
PuOr
RdBu
RdGy
RdYlBu
RdYlGn
Spectral
Cyclical color schemes
Sinebow
Turbo
Categorical color schemes
Category10
Accent
Dark2
Paired
Pastel1
Pastel2
Set1
Set2
Set3
Tableau10
Color scale
Auto
Scale
Auto
linear
log
sqrt
symlog
categorical
ordinal
Color options
Reverse
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Reducer
—
Auto
—
count
distinct
sum
min
max
mean
median
mode
Field
—
Field
—
Field
—
Mark
Auto
—
bar
dot
line
area
rule
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML