Published
Edited
Sep 1, 2021
5 forks
1 star
Insert cell
Insert cell
vl.markLine({size:3})
.data(temps_brasil_narrow)
.encode(
vl.x().fieldO("mês").sort(month_names),
vl.y().fieldQ("temp").scale({domain: [12, 28]}),
vl.color().fieldN("Cidade")
)
.title("Temperatura")
.width(500)
.height(300)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
temps_brasil = aq.loadCSV(url_gs)
Insert cell
Insert cell
temps_brasil
.view({height:240})
Insert cell
Insert cell
temps_brasil_colnames=temps_brasil.columnNames()
Insert cell
Insert cell
month_names = temps_brasil_colnames.slice(1)
Insert cell
temps_brasil
.fold(month_names,{as:['mês','temp']})
.view({height:240})
Insert cell
temps_brasil
.fold(aq.range(1,12),{as:['mês','temp']}) // nomeia as novas colunas)
.view({height:240})
Insert cell
temps_brasil
.fold(aq.not(0),{as:['mês','temp']})
.view({height:240})
Insert cell
Insert cell
typeof(temps_brasil
.fold(aq.not(0),{as:['mês','temp']})
.columnArray('temp')[0])
Insert cell
typeof(temps_brasil
.fold(aq.not(0),{as:['mês','temp']})
.columnArray('mês')[0])
Insert cell
Insert cell
viewof temps_brasil_narrow = temps_brasil
.fold(aq.not(0),{as:['mês','temp']})
//.derive({temp: d => +d.temp}) // '+' em js converte string para numérico
.view({height:240})
Insert cell
Insert cell
temps_brasil_narrow
.groupby('Cidade')
.rollup({ temp_media: op.mean('temp'), temp_minima: op.min('temp') } )
.orderby(aq.desc('temp_media'))
.view(10)
Insert cell
Insert cell
Insert cell
temps_brasil_narrow.view({height:240})
Insert cell
temps_brasil_narrow
.groupby('Cidade')
// sort: mantém as colunas nas ordens vistas na tabela narrow original
.pivot('mês','temp',{sort:false})
.view({height:240})
Insert cell
Insert cell
Insert cell
db_weather= Object.defineProperties(new SQLiteDatabaseClient(FileAttachment("weather.sqlite").arrayBuffer()),
{name: {value: "weather", enumerable: true}});
Insert cell
Insert cell
metadata=db_weather.query('pragma table_info(weather)')
Insert cell
col_names = metadata.map(row => row.name)
Insert cell
Insert cell
db_weather.queryRow('select count(*) as cnt from weather')
Insert cell
Insert cell
db_weather.query('select * from weather limit 10')
Insert cell
Insert cell
db_weather.query('select distinct location from weather')
Insert cell
db_weather.query('select location, count(*) as cnt from weather group by location')
Insert cell
Insert cell
weather_table=db_weather.query('select * from weather');
Insert cell
weather_arquero = aq.from(weather_table);
Insert cell
Insert cell
Insert cell
parseFloat("1.234")
Insert cell
+"1.2345"
Insert cell
precipitations_in_seattle = weather_arquero
.filter(d=>d.location==="Seattle")
// converte string numerico com '+'
.derive({precipitation: d=> +d.precipitation})
.columnArray('precipitation')
Insert cell
five_nums(precipitations_in_seattle)
Insert cell
Insert cell
weather_arquero
.filter(d=>d.location==="Seattle")
// converte para float
.derive({precipitation: d=> +d.precipitation})
.rollup({
linhas: op.count(),
min: op.min('precipitation'),
q1: op.quantile('precipitation', 0.25),
median: op.median('precipitation'),
q3: op.quantile('precipitation', 0.75),
max: op.max('precipitation')
})
.view()
Insert cell
Insert cell
weather_arquero
.groupby('weather')
.count()
.derive({total:op.sum('count')})
.derive({pct: d=>100*d.count/d.total })
.orderby(aq.desc('pct'))
.view()
Insert cell
Insert cell
Insert cell
weather_arquero_date_precipitation=weather_arquero
.select('location','date','precipitation')
// traduz nome das colunas
.rename({location:'cidade',date:'dia',precipitation:'precipitação'})
// muda o formato de strng para data e numérico
.derive({
dia: d=>op.parse_date(d.dia),
precipitação: d=> +d.precipitação
})
Insert cell
Insert cell
Insert cell
vl.markLine()
.data(weather_arquero_date_precipitation)
.encode(
vl.x().fieldT("dia").axis({title:"data"}),
vl.y().fieldQ("precipitação").scale({type: tipo_de_eixo_y==="linear" ? 'linear':'sqrt'}),
vl.color().fieldN("cidade")
)
.title("Precipitacao")
.width(500)
.render()
Insert cell
Insert cell
vl.markBoxplot()
.data(weather_arquero_date_precipitation)
.encode(
vl.x().fieldQ("precipitação").scale({type: tipo_de_eixo_y==="linear" ? 'linear':'sqrt'}),
vl.y().fieldN("cidade"),
vl.color().fieldN("cidade")
)
.title("Precipitacao")
.width(500)
.height(100)
.render()
Insert cell
Insert cell
vl.data(weather_arquero_date_precipitation)
.transform([{
window: [
{
field: "precipitação",
op: "mean",
as: "média_móvel"
}
],
frame: [-30, 30] // janela de 60 dias
}])
.encode(
vl.x().fieldT("dia").axis({title:"data"}),
vl.y().fieldQ("precipitação").scale({type: tipo_de_eixo_y==="linear" ? 'linear':'sqrt'})
)
.layer(
vl.markLine({"opacity": 0.3})
.encode(
vl.color().fieldN("cidade").scale({ range: ["red", "green"] })
),
vl.markLine({size:2})
.encode(
vl.y().fieldQ("média_móvel"),
vl.color().fieldN("cidade")
)
)
.title("Precipitação")
.width(500)
.render()
Insert cell
Insert cell
weather_arquero_date_precipitation.columnNames()
Insert cell
viewof weather_arquero_precip_bin = weather_arquero_date_precipitation
.groupby({
precip_bin: aq.bin('precipitação', {step:5}),
})
.count()
.orderby('precip_bin')
.view({height:240})
Insert cell
Insert cell
vl.markBar({color: "green", stroke:"black",width:20})
.data(weather_arquero_precip_bin)
.encode(
vl.x().fieldQ('precip_bin').scale({domain: [-2.5, 120]}),
vl.y().fieldQ('count').scale({type: 'log'})
)
.title("Histograma de precipitação em Seattle")
.width(800)
.render()
Insert cell
Insert cell
viewof temps_ny = weather_arquero
.filter(d=>d.location==="New York")
.rename({date:'data',precipitation:'precip'})
// converte precipit numerico
.derive({data: d=>op.parse_date(d.data),
precip: d=> +d.precip})
.view({height:240})
Insert cell
Insert cell
viewof temps_ny_narrow = temps_ny
.select('data','temp_min','temp_max')
.fold(['temp_min','temp_max'])
.view({height:240})
Insert cell
vl.markLine()
.data(temps_ny_narrow)
.encode(
vl.x().fieldT("data").axis({title:"data"}),
vl.y().fieldQ("value"),
vl.color().fieldN("key")
)
.title("Temp Min & Max em NY")
.width(500)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof covid_ano_semana = aq
.fromCSV(await FileAttachment("covid_ano_semana.csv").text())
.view({height:240})
Insert cell
Insert cell
vl.markLine()
.data(covid_ano_semana_fold)
.encode(
vl.x().fieldO("ano_semana"), //
vl.y().fieldQ("vacinados"),
vl.color().fieldN("país")
)
.title("Temperatura")
.width(500)
.height(300)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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