Public
Edited
Aug 14, 2023
Insert cell
# chicago / phoenix weather
Insert cell
import {
tidy,
groupBy,
summarize,
tally,
count,
n,
filter,
complete,
select,
pivotLonger,
negate,
sum,
mutate,
mutateWithSummary,
lag,
rename,
first,
max,
sliceMax,
mean,
map,
} from '@pbeshai/tidyjs'
Insert cell
phoenix = FileAttachment("KPHX.csv").csv()
Insert cell
chicago = FileAttachment("KMDW.csv").csv()
Insert cell
houston = FileAttachment("KHOU.csv").csv()
Insert cell
nyc = FileAttachment("KNYC.csv").csv()
Insert cell
seattle = FileAttachment("KSEA.csv").csv()
Insert cell
tidy_phoenix = tidy(
phoenix,
mutate({
'month': (d) => new Date(d.date).toLocaleString('default', { month: 'long' }),
'actual_mean_temp': (d) => Number(d.actual_mean_temp)
}),
groupBy('month', [
summarize({ mean_temp: mean('actual_mean_temp'), month_date: first('date') })
]),
mutate({
'month_date': (d) => new Date(d.month_date),
'city': "Phoenix"
}),
select(['-month'])
)
Insert cell
tidy_chicago = tidy(
chicago,
mutate({
'month': (d) => new Date(d.date).toLocaleString('default', { month: 'long' }),
'actual_mean_temp': (d) => Number(d.actual_mean_temp)
}),
groupBy('month', [
summarize({ mean_temp: mean('actual_mean_temp'), month_date: first('date') })
]),
mutate({
'month_date': (d) => new Date(d.month_date),
'city': "Chicago"
}),
select(['-month'])
)
Insert cell
tidy_houston = tidy(
houston,
mutate({
'month': (d) => new Date(d.date).toLocaleString('default', { month: 'long' }),
'actual_mean_temp': (d) => Number(d.actual_mean_temp)
}),
groupBy('month', [
summarize({ mean_temp: mean('actual_mean_temp'), month_date: first('date') })
]),
mutate({
'month_date': (d) => new Date(d.month_date),
'city': "Houston"
}),
select(['-month'])
)
Insert cell
tidy_nyc = tidy(
nyc,
mutate({
'month': (d) => new Date(d.date).toLocaleString('default', { month: 'long' }),
'actual_mean_temp': (d) => Number(d.actual_mean_temp)
}),
groupBy('month', [
summarize({ mean_temp: mean('actual_mean_temp'), month_date: first('date') })
]),
mutate({
'month_date': (d) => new Date(d.month_date),
'city': "New York City"
}),
select(['-month'])
)
Insert cell
tidy_seattle = tidy(
seattle,
mutate({
'month': (d) => new Date(d.date).toLocaleString('default', { month: 'long' }),
'actual_mean_temp': (d) => Number(d.actual_mean_temp)
}),
groupBy('month', [
summarize({ mean_temp: mean('actual_mean_temp'), month_date: first('date') })
]),
mutate({
'month_date': (d) => new Date(d.month_date),
'city': "Seattle"
}),
select(['-month'])
)
Insert cell
tidy_data = tidy_phoenix.concat(tidy_chicago).concat(tidy_houston).concat(tidy_nyc).concat(tidy_seattle)
Insert cell
Inputs.table(tidy_data)
Insert cell
phoenix_chicago = tidy_phoenix.concat(tidy_chicago)
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