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

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